function _datex_node_edit_form_date_validate in Datex 7.2
Same name and namespace in other branches
- 7.3 datex.module \_datex_node_edit_form_date_validate()
Element validation callback for date fields.
1 string reference to '_datex_node_edit_form_date_validate'
- datex_form_alter in ./
datex.module - Implements hook_form_alter().
File
- ./
datex.module, line 271 - Convert output of date_format() to Jalali in a patched drupal installation.
Code
function _datex_node_edit_form_date_validate($element, &$form_state, $form) {
if (empty($element['#value'])) {
return;
}
if (!($calendar = _datex_factory_with_defaults())) {
form_set_error($element['#name'], t('Invalid site language.'));
}
$element['#value'] = $calendar
->decor($element['#value'], FALSE);
$m = array();
$ok = preg_match('#^([0-9]{2,4})[-\\/\\\\]([0-9]{1,2})[-\\/\\\\]([0-9]{1,2})( {1,}([0-9]{1,2})\\:([0-9]{1,2})\\:([0-9]{1,2}))?#', $element['#value'], $m);
if ($ok && count($m) == 8) {
$date = array(
'hour' => $m[5],
'minute' => $m[6],
'second' => $m[7],
'year' => $m[1],
'month' => $m[2],
'day' => $m[3],
);
$calendar
->setDatetime($date);
$calendar
->setFormat('Y-m-d H:i:s O');
$element['#value'] = $calendar
->xformat();
form_set_value($element, $element['#value'], $form_state);
}
else {
form_set_error($element['#name'], t('You have to specify a valid date.'));
}
}