1 date_views_filter_handler_simple.inc date_views_filter_handler_simple::date_select_validate(&$form, &$form_state)

Validation hook for exposed filters that use the select widget.

This is to ensure the the user completes all parts of the date not just some parts. Only needed for the select widget.

File

core/modules/date/views/date_views_filter_handler_simple.inc, line 548
A standard Views filter for a single date field, using Date API form selectors and sql handling.

Class

date_views_filter_handler_simple
@file A standard Views filter for a single date field, using Date API form selectors and sql handling.

Code

function date_select_validate(&$form, &$form_state) {
  // If there are no values just return.
  if (empty($form['value']) && empty($form['min'])) {
    return;
  }
  $granularity = (!empty($form['min']['#date_format'])) ? date_format_order($form['min']['#date_format']) : date_format_order($form['value']['#date_format']);
  $filled = array();
  $value = backdrop_array_get_nested_value($form_state['input'], $form['#parents']);
  foreach ($granularity as $part) {
    if (isset($value['value']) && is_numeric($value['value'][$part])) {
      $filled[] = $part;
    }
  }
  if (!empty($filled) && count($filled) != count($granularity)) {
    $unfilled = array_diff($granularity, $filled);
    foreach ($unfilled as $part) {
      switch ($part) {
        case 'year':
          form_error($form['value'][$part], t('Please choose a year.'));
          break;

        case 'month':
          form_error($form['value'][$part], t('Please choose a month.'));
          break;

        case 'day':
          form_error($form['value'][$part], t('Please choose a day.'));
          break;

        case 'hour':
          form_error($form['value'][$part], t('Please choose an hour.'));
          break;

        case 'minute':
          form_error($form['value'][$part], t('Please choose a minute.'));
          break;

        case 'second':
          form_error($form['value'][$part], t('Please choose a second.'));
          break;
      }
    }
  }
}