1 form_test.module form_test_validate_required_form($form, &$form_state)

Form constructor to test the #required property.

File

core/modules/simpletest/tests/form_test.module, line 456
Helper module for the Form API tests.

Code

function form_test_validate_required_form($form, &$form_state) {
  $options = backdrop_map_assoc(array('foo', 'bar'));

  $form['textfield'] = array(
    '#type' => 'textfield',
    '#title' => 'Name',
    '#required' => TRUE,
    '#required_message' => 'Please enter a name.',
    // The following is not a real Form API property, it is only used in the
    // test validation to check the expected message.
    // See FormValidationTestCase::testCustomRequiredMessage() and
    // FormValidationTestCase::testCustomRequiredMessage().
    '#form_test_expected_message' => 'Please enter a name.',
  );
  $form['checkboxes'] = array(
    '#type' => 'checkboxes',
    '#title' => 'Checkboxes',
    '#options' => $options,
    '#required' => TRUE,
    '#required_message' => 'Please choose at least one option.',
    '#form_test_expected_message' => 'Please choose at least one option.',
  );
  $form['select'] = array(
    '#type' => 'select',
    '#title' => 'Select',
    '#options' => $options,
    '#required' => TRUE,
    '#form_test_expected_message' => 'Select field is required.',
    '#element_validate' => array('form_test_validate_select_element_validate'),
  );
  $form['radios'] = array(
    '#type' => 'radios',
    '#title' => 'Radios',
    '#options' => $options,
    '#required' => TRUE,
    '#form_test_expected_message' => 'Radios field is required.',
  );
  $form['radios_optional'] = array(
    '#type' => 'radios',
    '#title' => 'Radios (optional)',
    '#options' => $options,
  );
  $form['radios_optional_default_value_false'] = array(
    '#type' => 'radios',
    '#title' => 'Radios (optional, with a default value of FALSE)',
    '#options' => $options,
    '#default_value' => FALSE,
  );
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Submit');
  return $form;
}