You are here

function date_text_input_value in Date 6.2

Same name and namespace in other branches
  1. 5.2 date_api_elements.inc \date_text_input_value()
  2. 6 date_api_elements.inc \date_text_input_value()

Helper function for extracting a date value out of user input.

1 call to date_text_input_value()
date_text_validate in ./date_api_elements.inc
Validation for text input.
1 string reference to 'date_text_input_value'
date_input_value in date/date.module

File

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

Code

function date_text_input_value($element) {
  $form_values = $element['#value'];
  $granularity = date_format_order($element['#date_format']);
  $input = $form_values['date'];
  if (!$element['#required'] && trim($input) == '') {
    return NULL;
  }
  $value = date_limit_value(date_convert_from_custom($input, $element['#date_format']), $granularity);

  // If it creates a valid date, use it.
  if (date_is_valid($value, DATE_DATETIME, $granularity)) {
    return $value;
  }

  // TODO come back and try to find a way to use strtotime to guess
  // a valid value. Previous attempts to do it were too forgiving and
  // invalid input was just silently converted to 'now'.
  // See http://drupal.org/node/265076.
  return NULL;
}