diff options
Diffstat (limited to 'modules/simpletest/tests/form_test.module')
-rw-r--r-- | modules/simpletest/tests/form_test.module | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module index e4ac77b12..5d6527680 100644 --- a/modules/simpletest/tests/form_test.module +++ b/modules/simpletest/tests/form_test.module @@ -151,6 +151,14 @@ function form_test_menu() { 'type' => MENU_CALLBACK, ); + $items['form-test/redirect'] = array( + 'title' => 'Redirect test', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('form_test_redirect'), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + $items['form_test/form-labels'] = array( 'title' => 'Form label test', 'page callback' => 'drupal_get_form', @@ -1644,6 +1652,43 @@ function form_test_clicked_button_submit($form, &$form_state) { } /** + * Form builder to detect form redirect. + */ +function form_test_redirect($form, &$form_state) { + $form['redirection'] = array( + '#type' => 'checkbox', + '#title' => t('Use redirection'), + ); + $form['destination'] = array( + '#type' => 'textfield', + '#title' => t('Redirect destination'), + '#states' => array( + 'visible' => array( + ':input[name="redirection"]' => array('checked' => TRUE), + ), + ), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + return $form; +} + +/** + * Form submit handler to test different redirect behaviours. + */ +function form_test_redirect_submit(&$form, &$form_state) { + if (!empty($form_state['values']['redirection'])) { + $form_state['redirect'] = !empty($form_state['values']['destination']) ? $form_state['values']['destination'] : NULL; + } + else { + $form_state['redirect'] = FALSE; + } +} + +/** * Implements hook_form_FORM_ID_alter() for the registration form. */ function form_test_form_user_register_form_alter(&$form, &$form_state) { |