function date_text_validate in Date 7
Same name and namespace in other branches
- 5.2 date_api_elements.inc \date_text_validate()
- 5 date.inc \date_text_validate()
- 6.2 date_api_elements.inc \date_text_validate()
- 6 date_api_elements.inc \date_text_validate()
- 7.3 date_api/date_api_elements.inc \date_text_validate()
- 7.2 date_api/date_api_elements.inc \date_text_validate()
Validation for text input.
When used as a Views widget, the validation step always gets triggered, even with no form submission. Before form submission $element['#value'] contains a string, after submission it contains an array.
1 string reference to 'date_text_validate'
- date_text_element_process in date_api/
date_api_elements.inc - Text date input form.
File
- date_api/
date_api_elements.inc, line 248 - 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, &$form_state) {
if (is_string($element['#value'])) {
return;
}
$input_exists = NULL;
$input = drupal_array_get_nested_value($form_state['input'], $element['#parents'], $input_exists);
$label = !empty($element['#date_title']) ? $element['#date_title'] : (!empty($element['#title']) ? $element['#title'] : '');
$date = date_text_input_date($element, $input);
if (empty($date) && !empty($element['#required'])) {
form_error($element, t('A valid date is required for %title.', array(
'%title' => $label,
)));
}
elseif (empty($date) && !empty($element['#value']['date'])) {
form_error($element, t('%title is invalid.', array(
'%title' => $label,
)));
}
elseif (!empty($date->errors)) {
form_error($element, implode('<br />', $date->errors));
}
elseif (!empty($date)) {
$value = $date
->format(DATE_FORMAT_DATETIME);
form_set_value($element, $value, $form_state);
}
else {
form_set_value($element, NULL, $form_state);
}
}