1 form_example_tutorial.inc form_example_tutorial_9_validate($form, &$form_state)

Validate function for form_example_tutorial_9().

Adds logic to validate the form to check the validity of the new fields, if they exist.

File

modules/examples/form_example/form_example_tutorial.inc, line 650
This is the form API tutorial.

Code

function form_example_tutorial_9_validate($form, &$form_state) {

  for ($i = 1; $i <= $form_state['num_names']; $i++) {
    $year_of_birth = $form_state['values']['name'][$i]['year_of_birth'];

    if ($year_of_birth && ($year_of_birth < 1900 || $year_of_birth > 2000)) {
      form_set_error("name][$i][year_of_birth", t('Enter a year between 1900 and 2000.'));
    }
  }
}