Commit 7af1ba1e authored by Dries's avatar Dries

- Patch #99087 by Eaton, grugnog2 et al: multistep forms shouldn't fill the session table.

parent 627d4267
......@@ -53,11 +53,11 @@ function drupal_get_form($form_id) {
// then go on to the one that was requested if everything works.
$form_build_id = md5(mt_rand());
if (isset($_POST['form_build_id']) && isset($_SESSION['form'][$_POST['form_build_id']]) && $_POST['form_id'] == $form_id) {
if (isset($_POST['form_build_id']) && isset($_SESSION['form'][$_POST['form_build_id']]['args']) && $_POST['form_id'] == $form_id) {
// There's a previously stored multi-step form. We should handle
// IT first.
$stored = TRUE;
$args = $_SESSION['form'][$_POST['form_build_id']];
$args = $_SESSION['form'][$_POST['form_build_id']]['args'];
$form = call_user_func_array('drupal_retrieve_form', $args);
}
else {
......@@ -67,7 +67,9 @@ function drupal_get_form($form_id) {
$args = func_get_args();
$form = call_user_func_array('drupal_retrieve_form', $args);
if (isset($form['#multistep']) && $form['#multistep']) {
$_SESSION['form'][$form_build_id] = $args;
// Clean up old multistep form session data.
_drupal_clean_form_sessions();
$_SESSION['form'][$form_build_id] = array('timestamp' => time(), 'args' => $args);
$form['#build_id'] = $form_build_id;
}
$stored = FALSE;
......@@ -97,6 +99,21 @@ function drupal_get_form($form_id) {
}
/**
* Remove form information that's at least a day old from the
* $_SESSION['form'] array.
*/
function _drupal_clean_form_sessions() {
if (isset($_SESSION['form'])) {
foreach ($_SESSION['form'] as $build_id => $data) {
if ($data['timestamp'] < (time() - 84600)) {
unset($_SESSION['form'][$build_id]);
}
}
}
}
/**
* Retrieves a form using a form_id, populates it with $form_values,
* processes it, and returns any validation errors encountered. This
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment