[php] posting hidden value

hey there, i have three pages: (1) bookingfacilities.php (2) booking_now.php (3) successfulbooking.php and they are link together.

i want to pass data from bookingfacilities.php to successfulbooking.php by using hidden field/value. however, my data doesn't get print out in successfulbooking.php.

here are my codes:

  • from 'booking_now.php': $date="$day-$month-$year";

  • from 'successfulbooking.php'; <input type="hidden" name="date" id="hiddenField" value="<?php print "$date" ?>"/>

i would greatly appreciate your help as my project is due tomorrow :(

This question is related to php forms hidden

The answer is


You should never assume register_global_variables is turned on. Even if it is, it's deprecated and you should never use it that way.

Refer directly to the $_POST or $_GET variables. Most likely your form is POSTing, so you'd want your code to look something along the lines of this:

<input type="hidden" name="date" id="hiddenField" value="<?php echo $_POST['date'] ?>" />

If this doesn't work for you right away, print out the $_POST or $_GET variable on the page that would have the hidden form field and determine exactly what you want and refer to it.

echo "<pre>";
print_r($_POST);
echo "</pre>";

I'm not sure what you just did there, but from what I can tell this is what you're asking for:

bookingfacilities.php

<form action="successfulbooking.php" method="post">
    <input type="hidden" name="date" value="<?php echo $date; ?>">  
    <input type="submit" value="Submit Form">
</form>

successfulbooking.php

<?php
    $date = $_POST['date'];
    // add code here
?>

Not sure what you want to do with that third page(booking_now.php) too.


You have to use $_POST['date'] instead of $date if it's coming from a POST request ($_GET if it's a GET request).


Maybe a little late to the party but why don't you use sessions to store your data?

bookingfacilities.php

session_start();
$_SESSION['form_date'] = $date;

successfulbooking.php

session_start();
$date = $_SESSION['form_date']; 

Nobody will see this.


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to forms

How do I hide the PHP explode delimiter from submitted form results? React - clearing an input value after form submit How to prevent page from reloading after form submit - JQuery Input type number "only numeric value" validation Redirecting to a page after submitting form in HTML Clearing input in vuejs form Cleanest way to reset forms Reactjs - Form input validation No value accessor for form control TypeScript-'s Angular Framework Error - "There is no directive with exportAs set to ngForm"

Examples related to hidden

bootstrap 4 responsive utilities visible / hidden xs sm lg not working How to get current formatted date dd/mm/yyyy in Javascript and append it to an input Hidden property of a button in HTML What's the best way to identify hidden characters in the result of a query in SQL Server (Query Analyzer)? Making a button invisible by clicking another button in HTML Check div is hidden using jquery Windows batch script to unhide files hidden by virus jQuery - Detect value change on hidden input field posting hidden value Make one div visible and another invisible