form_test_storage_form($form, &$form_state)A multistep form for testing the form storage.
It uses two steps for editing a virtual "thing". Any changes to it are saved in the form storage and have to be present during any step. By setting the request parameter "cache" the form can be tested with caching enabled, as it would be the case, if the form would contain some #ajax callbacks.
form_test_storage_form_submit()
modules/simpletest/tests/form_test.module, line 382
<?php
function form_test_storage_form($form, &$form_state) {
if ($form_state['rebuild']) {
$form_state['input'] = array();
}
// Initialize
if (empty($form_state['storage'])) {
if (empty($form_state['input'])) {
$_SESSION['constructions'] = 0;
}
// Put the initial thing into the storage
$form_state['storage'] = array(
'thing' => array(
'title' => 'none',
'value' => '',
),
);
}
// Count how often the form is constructed.
$_SESSION['constructions']++;
drupal_set_message("Form constructions: ". $_SESSION['constructions']);
$form['title'] = array(
'#type' => 'textfield',
'#title' => 'Title',
'#default_value' => $form_state['storage']['thing']['title'],
'#required' => TRUE,
);
$form['value'] = array(
'#type' => 'textfield',
'#title' => 'Value',
'#default_value' => $form_state['storage']['thing']['value'],
'#element_validate' => array('form_test_storage_element_validate_value_cached'),
);
$form['button'] = array(
'#type' => 'button',
'#value' => 'Reload',
// Reload the form (don't rebuild), thus we start at the initial step again.
);
$form['continue_button'] = array(
'#type' => 'button',
'#value' => 'Reset',
// Rebuilds the form without keeping the values.
'#validate' => array('form_storage_test_form_continue_validate'),
);
$form['continue_submit'] = array(
'#type' => 'submit',
'#value' => 'Continue submit',
'#submit' => array('form_storage_test_form_continue_submit'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);
if (isset($_REQUEST['cache'])) {
// Manually activate caching, so we can test that the storage keeps working
// when it's enabled.
$form_state['cache'] = TRUE;
}
return $form;
}
?>