You are here

function date_text_validate in Date 5.2

Same name and namespace in other branches
  1. 5 date.inc \date_text_validate()
  2. 6.2 date_api_elements.inc \date_text_validate()
  3. 6 date_api_elements.inc \date_text_validate()
  4. 7.3 date_api/date_api_elements.inc \date_text_validate()
  5. 7 date_api/date_api_elements.inc \date_text_validate()
  6. 7.2 date_api/date_api_elements.inc \date_text_validate()

Validation for text input.

File

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

Code

function date_text_validate($element) {
  $value = date_text_input_value($element);

  // If the field is empty and not required, set it to empty and return.
  if (empty($value) && !$element['#required']) {
    form_set_value($element, NULL);
    return;
  }
  if (!empty($value)) {
    form_set_value($element, $value);
  }
  else {
    $error_field = implode('][', $element['#parents']);
    form_set_error($error_field, t('A valid date is required for %title.', array(
      '%title' => $element['#title'],
    )));
  }
}