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: http://$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/printw....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