You are here

function date_year_range_validate in Date 8

Same name and namespace in other branches
  1. 7.3 date_api/date_api_elements.inc \date_year_range_validate()
  2. 7.2 date_api/date_api_elements.inc \date_year_range_validate()

Element validation function for the date_year_range form element.

1 string reference to 'date_year_range_validate'
_date_api_element_info in date_api/date_api_elements.inc
Implements hook_element_info().

File

date_api/date_api_elements.inc, line 159
Date API elements themes and validation. This file is only included during the edit process to reduce memory usage.

Code

function date_year_range_validate(&$element, &$form_state) {

  // Recombine the two submitted form values into the -3:+3 format we will
  // validate and save.
  $year_range_submitted = drupal_array_get_nested_value($form_state['values'], $element['#parents']);
  $year_range = $year_range_submitted['years_back'] . ':' . $year_range_submitted['years_forward'];
  drupal_array_set_nested_value($form_state['values'], $element['#parents'], $year_range);
  if (!date_range_valid($year_range)) {
    form_error($element['years_back'], t('Starting year must be in the format -9, or an absolute year such as 1980.'));
    form_error($element['years_forward'], t('Ending year must be in the format +9, or an absolute year such as 2030.'));
  }
}