View Full Version : Pass Form Data Using $_SESSION?

02-08-2005, 04:44 PM
I'm having a bit of trouble with a script I'm working on. The idea is my order.php page by default will display a form for the user to fill in their details and what equipment they want to order. There is ten possibly types of equipment for them to order, if they select say types 2, 5, and 9 then they need to fill in more info as there are individual forms to go with those orders. So the idea is that on submission of the form they are presented with another form, generated by the same order.php file, which they fill in, and are then presented with the next needed form etc. This isn't a prob, i've got this all pretty much working, the problem i'm having is that i'm passing the form data using hidden fields that have the values as <?php echo $_POST['name']; ?> when the form is submitted, this works fine, however when the page has loaded again the values that were originally entered are lost.

The idea is i need to be able to successfull carry over all submitted data over a possible seven forms/pages until the data is compiled in an email and sent off. I read that this data can be easily stored and carried over with sessions but i haven't been able to find any info on how to do this. Either that or is there a better/easier way of passing the data more easily?

Cheers in advance.

02-08-2005, 05:08 PM
Well you could use sessions. You could just set all needed fields in the $_SESSION array and viola.

You could use Hidden fields...

Or you could store the temporary data in a DB or a file.

02-08-2005, 05:31 PM
How do you store them in the $_SESSION array?

Currently I have code along the lines of:



$_SESSION["qtylaptop"] = $_POST['qtylaptop'];
$_SESSION["qtyprinter"] = $_POST['qtyprinter'];
$_SESSION["qtymobile"] = $_POST['qtymobile'];
$_SESSION["qtypager"] = $_POST['qtypager'];
$_SESSION["qtyusbkey"] = $_POST['qtyusbkey'];

if (!empty($_SESSION['qtylaptop']) && ($_SESSION['laptopdone'] != "true")) {
//display form for laptop
$_SESSION['laptopdone'] = "true";

} else if (!empty($_SESSION['qtyprinter']) && ($_SESSION['printerdone'] != "true")) {
//display form for printer
$_SESSION['printerdone'] = "true";

} else if (!empty($_SESSION['qtyusbkey']) && ($_SESSION['usbkeydone'] != "true")) {
//display form for usb key
$_SESSION['usbkeydone'] = "true";

} else {
//display summary of order/confirmation page

After submission i get the laptop page (provided it has been ordered that is), but after that I just get a blank page when the laptop form is submitted so i dont think the data is being passed.

02-08-2005, 05:41 PM
The way you're setting the $_SESSION vars seems fine. What happens if you echo the $_SESSION variables right after you call them, do they return any values?

02-08-2005, 05:53 PM
I just tested this by entering data into the two of the fields that should return an extra form. After the default form was submitted and the first form returned, the value for the second value was successfully echoed. After submitting that form though the value was lost. This is the code i used to test it:

if (!$_SESSION['qtypager']) {
echo "The session data hasn't been passed";
} else {
echo $_SESSION['qtypager'];

In the default form i entered the values for the fields qtylaptop and qtypager. They seem to be lost after one page reload.

EDIT: Just ran phpinfo(); this is what i says about sessions:

session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.referer_check no value no value
session.save_handler files files
session.save_path no value no value
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid Off Off

02-08-2005, 08:56 PM
Ahh nevermind, figured it out now. Thanks to all who replied and cheers to brandon for the help in solving this.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum