Jump to content

[SOLVED] Newbie question :)


Leadwing

Recommended Posts

Hi there,

I have a form with multiple pages.

In order to pass data from the the first page of a form to the second page, i understand you need to use...

 

<input type="hidden" name="$_POST['name']" />

 

...in the second page.

 

But it doesnt seem to work (when i try to display it on the third page)

 

Also how do I get the data to go through a "process", which is like, in between the form pages?

 

Helpsies would be greatly apreciated :)

Link to comment
Share on other sites

If I understand you correct, I would do the following:

 

Lets say pages are page1.php, page2.php and page3.php, and I guess you want to have the form on page 3 to send all the information entered since page 1. If we have one text field on each page, and the first is for your given name, second for your surname and third for your age, it could look like this:

 

page1.php:

...
<form action="page2.php" method="post">
<fieldset>
	<legend>Personal information</legend>
		<label for="givenname">Given name:</label>
		<input id="givenname" name="givenname" type="text" />
</fieldset>
<input type="submit" value="Go to page 2" />
</form>
...

 

page2.php:

...
<form action="page3.php" method="post">
<fieldset>
	<legend>Personal information</legend>
		<label for="surname">Surname:</label>
		<input id="surname" name="surname" type="text" />
		<input type="hidden" name="givenname" value="<?php echo $_POST['givenname']; ?>" />
</fieldset>
<input type="submit" value="Go to page 3" />
</form>
...

 

page3.php:

...
<form action="lastpage.php" method="post">
<fieldset>
	<legend>Personal information</legend>
		<label for="age">Age:</label>
		<input id="age" name="age" type="text" />
		<input type="hidden" name="givenname" value="<?php echo $_POST['givenname']; ?>" />
		<input type="hidden" name="surname" value="<?php echo $_POST['surname']; ?>" />
</fieldset>
<input type="submit" value="Send my information" />
</form>
...

 

lastpage.php would be the page you eventually send all the information to. Good luck :)

Link to comment
Share on other sites

Thanks, that works nicely :)

One last thing...

 

I have a page in between page 2 and 3, its a code to redirect to page 3 or another page (I wont go into details).

But my question is how can I use that

 

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

 

On a page which doesn't have a form? - Just an  if/elseif command?

 

Hope that makes sense.

 

 

 

Link to comment
Share on other sites

That depends on what you want to do with the data. If you want to redirect it along, you should look into sessions, which can store data temporarily (and thus across pages, not depending on forms and text fields). In your example you could store the form data in sessions, like this:

 

page_in_between_2_and_3.php ;)

...
<?php
// storing the given name from page 1 and 2
$_SESSION['givenname'] = $_POST['givenname'];
// storing the surname from page 2
$_SESSION['surname'] = $_POST['surname'];
?>
...

 

And you will then be able to extract the data again on whatever page you like, like this:

<?php echo $_SESSION['givenname']; ?>

 

I recommend you to read this short article on sessions: http://www.tizag.com/phpT/phpsessions.php, because you can't store any session data without first starting a session. Just read it, or your code wont work =)

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.