You are here

function form_test_validate_form in Drupal 7

Form builder for testing drupal_validate_form().

Serves for testing form processing and alterations by form validation handlers, especially for the case of a validation error:

  • form_set_value() should be able to alter submitted values in $form_state['values'] without affecting the form element.
  • #element_validate handlers should be able to alter the $element in the form structure and the alterations should be contained in the rebuilt form.
  • #validate handlers should be able to alter the $form and the alterations should be contained in the rebuilt form.
1 string reference to 'form_test_validate_form'
form_test_menu in modules/simpletest/tests/form_test.module
Implements hook_menu().

File

modules/simpletest/tests/form_test.module, line 320
Helper module for the form API tests.

Code

function form_test_validate_form($form, &$form_state) {
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => 'Name',
    '#default_value' => '',
    '#element_validate' => array(
      'form_test_element_validate_name',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
  );

  // To simplify this test, enable form caching and use form storage to
  // remember our alteration.
  $form_state['cache'] = TRUE;
  return $form;
}