April 26th, 2013, 02:23 PM
-
How do you send information from a from to 2 pages?
I can send information from one page to another $_POST
But how do I send information from a form from the second to the third page?
Do I use a cookie or can I a simpler method?
Thanks
April 26th, 2013, 02:46 PM
-
This is typically done in one of two ways:
1. The information from each page is stored in the session. This is best if you have full control over everything, most importantly the code.
2. Each page submits data from the previous page as hidden fields (plus whatever new fields it has to add). This can mean you have to validate data a lot and so is only really worth considering if you're breaking an existing large form into multiple small pages and it's only the final page that does any real work (eg, validating or processing) with the data.
April 26th, 2013, 03:37 PM
-
Re:
How would one go about storing information in a session?
I appreciate your help
April 26th, 2013, 04:48 PM
-
1. Needs a session_start(), naturally.
2. On the first page generate a fairly random ID. Stick that in the form as a hidden field, and in every subsequent form too.
3. When each page is submitted, validate the data and store the array in $_SESSION[...][the random ID]. You can use a subarray for each page, or array_merge() everything together.
4. Redirect to and/or show the next pages.
5. Finally, all the data has been collected in there. Use it and unset() it.
April 27th, 2013, 03:41 AM
-
Originally Posted by requinix
1. Needs a session_start(), naturally.
2. On the first page generate a fairly random ID. Stick that in the form as a hidden field, and in every subsequent form too.
3. When each page is submitted, validate the data and store the array in $_SESSION[...][the random ID]. You can use a subarray for each page, or array_merge() everything together.
4. Redirect to and/or show the next pages.
5. Finally, all the data has been collected in there. Use it and unset() it.
wrong answer
:
1. type in google.com in your fave browser
2. search for "Sessions + PHP +tutorial" or something similar
3. go to one of the links provided..
see i got 3 steps to your 5 
but then again, i understand this might be hard for some to do..
April 27th, 2013, 05:16 AM
-
Oh yeah? How about one:
1. Google it.
Yeah, giving fewer steps doesn't make it better advice.
Comments on this post
April 27th, 2013, 08:06 AM
-
Re:
Thanks requinix for taking the time to answer.
I will experiment and let you if it works.
April 28th, 2013, 10:44 AM
-
Re:
I'm still having problems with the $_SESSION code.
I can't retrieve the info on the next page.
After looking at the manual (which I think lacks enough examples / explanation) I came to this:
<?php
session_start();
if (empty($_SESSION['count'])) {
$_SESSION['count'] = 1;
} else {
$_SESSION['count']++;
}
?>
<html>
<form enctype="multipart/form-data" method="POST" action="ads.php?<?php echo $_SESSION["count"]; ?>" />
<input type="hidden" name="PHPSESSID" value="<?php echo $_SESSION["count"]; ?>" />
Name:<input type="text" name ="name" /><br />
Book:<input type="text" name ="book" /><br />
Subject:<input type="text" name ="subject" /><br />
Price (CAN):<input type="text" name ="price" /><br />
Description: <br /><textarea cols="40" rows="5" name="description">
</textarea><br />
Click to upload:<input type="file" name="pix" /><br />
<input type="submit" name="Upload" value="Upload Picture" />
</form>
</html>
I managed to get the ID to send in a link to the other page.
But on the next page, when I write:
<?php
echo $_SESSION['PHPDSESSID'];
echo "<b>Name: </b>" . $_SESSION['name'] . "<br />";
?>
How do I retrieve the info from the URL using $_SESSION? Also how do I generate the proper text from $_SESSION using the ID from the link.
I'm open to anything you have in mind.
April 29th, 2013, 06:38 PM
-
Here is a very simple untested example:
page1.php:
PHP Code:
<form action="page2.php" method="POST">
<input type="text" name="first_name" />
</form>
page2.php:
PHP Code:
<?php
session_start();
$_SESSION['first_name'] = $_POST['first_name'];
?>
<form action="page3.php" method="POST">
<input type="text" name="last_name" />
</form>
page3.php:
PHP Code:
<?php
session_start();
echo "Your name: " . htmlspecialchars($_SESSION['first_name']) . ' ' . htmlspecialchars($_POST['last_name']);
This has the limitation of only allowing a particular user to be filling out one series of forms at a time. In order to overcome that, you would have to use the extra steps mentioned in post 4.
PHP FAQ
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
April 30th, 2013, 01:34 PM
-
Re:
Thanks for the answer.
I got it working.