function form_example_tutorial_9_validate

Validate function for form_example_tutorial_9().

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

Related topics

File

form_example/form_example_tutorial.inc, line 698

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.'));
        }
    }
}