Form Session Data
Posted: Thu Feb 05, 2009 9:44 am
OK, I built a rather large order form with 4 steps all in the same file (form action reloads the same page). If you click back in the browser, all information on the previous screen is lost. Now I am retrospectively trying to build in some sort of memory for this form, so I've been trying to fit sessions in there somewhere but nothing is working.
At the start of the page, I have this:
And then I'm echoing all the session variables in the <input> values of the form. This doesn't seem to do anything though. If I loop through the $_SESSION array at the start of the page and just print out all the values to see, they all exist but they don't get put into the form fields when you click back.
Is this a problem related to the fact that each step of the form is not a separate file? I didn't think it would make a difference if the form is submitting to itself or a new page.
----------------------------------------------------------------------------------------------------------------
It might be easier for someone to start explaining from the beginning, and ignore what I've done so far. So here is what I'm trying to do:
At the start of the page, I have this:
Code: Select all
ob_start();
require(INCLUDES . 'header.php');
// Remove slashes and white space
$_POST = cleanVars($_POST);
session_start();
foreach ($_POST as $key => $val) {
$_SESSION[$key] = $val;
}
ob_end_flush();Is this a problem related to the fact that each step of the form is not a separate file? I didn't think it would make a difference if the form is submitting to itself or a new page.
----------------------------------------------------------------------------------------------------------------
It might be easier for someone to start explaining from the beginning, and ignore what I've done so far. So here is what I'm trying to do:
- When the order form is started, session starts.
- If the user goes backwards or forwards through the 4 steps, data needs to appear again in the fields of previously visited pages.
- When the order is finalised on the last step, they see a confirmation screen (we're still on the same page as before). At this point, the session should be destroyed so if they refresh the confirmation page or return to the order page again, it will start a new order.