Jump to content

passing values in hidden fields on a form


sambib

Recommended Posts

Hi,

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:

[color=blue][font=Verdana]<?php
if(isset($_POST['submit'])) {

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

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

[b]The values don't however get passed from here on....?[/b]:

[color=blue]<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" />
</label>
</form>[/color]

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

[color=blue]if(isset($_POST['submit'])) {

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

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

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....?

Link to comment
Share on other sites

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

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

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

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.
Link to comment
Share on other sites

cheers....

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 [color=blue]<?=[/color] with [color=blue]<?php[/color], so the 'echo' wasn't required previously...

so there you go, you learn something new everyday....
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.