Jump to content


passing values in hidden fields on a form

  • Please log in to reply
2 replies to this topic

#1 sambib

  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 12 October 2006 - 03:22 AM


I've got a long php/html form which I've broken up into pages for usability and I want to pass the collected vlaues from page to page in hidden fields, however it's not working.

the data from the first page gets passed to the second like so:

if(isset($_POST['submit'])) {

echo "<p>you entered: $dateOfBirth</p>";
echo "<p>you entered: " . ($_POST['firstName']) . "</p>";

this is just for testing and at this stage it works (ie. the values appear on the page as i expect)

The values don't however get passed from here on....?:

<form id="downloadForm" name="downloadForm" action="surveyform3.php" method="post">

<input type="hidden" name="firstName" value="<?php ($_POST['firstName']); ?>" />
<input type="hidden" name="dateOfBirth" value="<?php $dateOfBirth; ?>" />

<label for="submit" class="required"><span class="labelText">Continue to Page 3 of the Form:</span>
<input id="submit" type="submit" name="submit" value="Next Page" />

Here's the code for the following page and these echo statements don't show any values being passed:

if(isset($_POST['submit'])) {

echo "<p>you entered: " . ($_POST['dateOfBirth']) . "</p>";

echo "<p>you entered: " . ($_POST['firstName']) . "</p>";

the form continues......

I've recently upgraded to php5 and I'm sure this was working a few weeks ago before the upgrade, so is there some syntax error or anything else I've missed....?

#2 JasonLewis

  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 12 October 2006 - 03:29 AM

ok this error has been answered millions of times here. when your making the value="" your not echoing your php value...

<input type="hidden" name="firstName" value="<?php ($_POST['firstName']); ?>" />

should be this:
<input type="hidden" name="firstName" value="<?php echo $_POST['firstName']; ?>" />

see how I added the echo $_POST['firstName']. Because you just had it as the variable php wasn't doing anything with it. take more care next time and good luck.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#3 sambib

  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 12 October 2006 - 05:53 AM


when i was using php4 that code looked like this (and worked):

<input type="hidden" name="firstName" value="<?= $_POST['firstName']; ?>" />

but that doesn't work in php5 so i replace the <?= with <?php, so the 'echo' wasn't required previously...

so there you go, you learn something new everyday....

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users