You are here

function _date_field_validate in Date 6

Same name and namespace in other branches
  1. 5.2 date/date_elements.inc \_date_field_validate()
  2. 6.2 date/date_elements.inc \_date_field_validate()

Private implementation of hook_field validate operation.

1 call to _date_field_validate()
date_field in date/date.module
Implementation of hook_field().

File

date/date_elements.inc, line 13
Date forms and form themes and validation.

Code

function _date_field_validate($op, &$node, $field, &$items, $teaser, $page) {
  $field_name = $field['field_name'];

  // Don't try to validate if there were any errors before this point
  // since the element won't have been munged back into a date.
  if (!form_get_errors()) {
    foreach ($items as $delta => $item) {
      $process = date_process_values($field);
      foreach ($process as $processed) {
        $error_field = $field['field_name'] . '][' . $delta . '][' . $processed;
        $error_field .= $field['widget']['type'] == 'date_select' ? '][year' : '';
        if ($processed == 'value' && $field['todate'] && !date_is_valid($item['value'], $field['type']) && date_is_valid($item['value2'], $field['type'])) {
          form_set_error($error_field, t("A 'From date' date is required for %field %delta", array(
            '%delta' => $field['multiple'] ? intval($delta + 1) : '',
            '%field' => t($field['widget']['label']),
          )));
        }
        if ($processed == 'value2' && $field['todate'] == 'required' && ($field['required'] && date_is_valid($item['value'], $field['type']) && !date_is_valid($item['value2'], $field['type']))) {
          form_set_error($error_field, t("A 'To date' is required for %field %delta", array(
            '%delta' => $field['multiple'] ? intval($delta + 1) : '',
            '%field' => t($field['widget']['label']),
          )));
        }
      }
    }
  }
}