I have a form that will be preserving form data prior to processing the form data. Upon clicking a certain submit button you will go to another PHP script that will contain the following code:
if (strcmp(strtolower($POST['submit']), 'apply') != 0) { // GO BACK TO grad_application with $SESSION
session_start();
if (sizeof($POST) > 0) $SESSION['post'] = $POST;
if (sizeof($GET) > 0) $SESSION['get'] = $GET;
header("Location: [url]http://[/url]$SERVER_NAME${devpath}grad_application.php?" . Session_Name() . '=' . Session_Id());
}
Upon redirection back to the original PHP form script I will include an "HTML" file (its extension is HTML but it's actually PHP) that should prepopulate the form fields with the data from $_SESSION. At the top of my page I have:
session_start();
However, while I see the PHPSESSID in my query string I do not see any of my form elements populated. This is how I am parsing $_SESSION in the "HTML" file:
/----------------------------------------------------------------------------------------------
Unclear as to how $POST and $GET vars are set, so as a backup, save them here in macros.inc
------------------------------------------------------------------------------------------------/
foreach ($_POST as $key => $val) {
if (!isset(${$key})) ${$key} = $val;
}
foreach ($_GET as $key => $val) {
if (!isset(${$key})) ${$key} = $val;
}
if (preg_match('/grad_application.php/i', $REQUEST_URI) && isset($SESSION['post'])) {
foreach ($SESSION['post'] as $key => $val) {
$blah .= "key = $key and val = $val<P>\n";
if (!isset(${$key})) ${$key} = $val;
}
}
if (preg_match('/grad_application.php/i', $REQUEST_URI) && isset($SESSION['get'])) {
foreach ($SESSION['get'] as $key => $val) {
if (!isset(${$key})) ${$key} = $val;
}
}
//---END OF FORM VAR DYNAMIC SETTING BLOCK------------------------------------------------------
This was all based on php.net information on sessions at: http://us4.php.net/manual/en/function.session-start.php
and at
http://us4.php.net/manual/en/printwn/language.variables.predefined.php
I've never had any success with sessions to be honest. Maybe I'm approaching this whole thing wrong. Bottom line is that I want to produce a form that has a button that will produce more form elements upon click while retaining everything you typed so far.
Phil