You are here

function _datex_node_edit_form_date_validate in Datex 7.3

Same name and namespace in other branches
  1. 7.2 datex.module \_datex_node_edit_form_date_validate()

Form element validation callback for node edit form.

1 string reference to '_datex_node_edit_form_date_validate'
datex_form_alter in ./datex.module
Implements hook_form_alter().

File

./datex.module, line 413
Datex main module file, Datex adds php-intl support to drupal.

Code

function _datex_node_edit_form_date_validate($el, &$fs, $f) {
  if (!$fs['#datexified'] || empty($el['#value'])) {
    return;
  }
  $calendar = datex_factory();
  if (!$calendar) {
    form_set_error($el['#name'], t('Invalid site language.'));
  }
  $m = [];
  $pattern = '#^([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}))?#';
  $ok = preg_match($pattern, $el['#value'], $m);
  if ($ok && count($m) == 8) {
    $calendar
      ->setDateLocale($m[1], $m[2], $m[3]);
    $calendar
      ->setTime($m[5], $m[6], $m[7]);
    $el['#value'] = $calendar
      ->xFormat('Y-m-d H:i:s O');
    form_set_value($el, $el['#value'], $fs);
  }
  else {
    form_set_error($el['#name'], t('You have to specify a valid date.'));
  }
}