function form_storage_test_form in SimpleTest 7
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.
See also
form_storage_test_form_submit().
1 string reference to 'form_storage_test_form'
- form_test_menu in tests/
form_test.module - Implement hook_menu().
File
- tests/
form_test.module, line 276 - Helper module for the form API tests.
Code
function form_storage_test_form($form, &$form_state) {
// Initialize
if (!isset($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' => '',
),
);
$form_state['storage'] += array(
'step' => 1,
);
}
// Count how often the form is constructed
$_SESSION['constructions']++;
if ($form_state['storage']['step'] == 1) {
$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'],
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Continue',
);
}
else {
$form['body'] = array(
'#value' => 'This is the second step.',
);
$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['#cache'] = TRUE;
}
return $form;
}