Jump to content

Archived

This topic is now archived and is closed to further replies.

sambib

passing values in hidden fields on a form

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

Share this post


Link to post
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.

Share this post


Link to post
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....

Share this post


Link to post
Share on other sites

×

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.