You are here

function date_popup_validate in Date 6

Same name and namespace in other branches
  1. 5.2 date_popup/date_popup.module \date_popup_validate()
  2. 6.2 date_popup/date_popup.module \date_popup_validate()
  3. 7.3 date_popup/date_popup.module \date_popup_validate()
  4. 7 date_popup/date_popup.module \date_popup_validate()
  5. 7.2 date_popup/date_popup.module \date_popup_validate()

Massage the input values back into a single date.

1 string reference to 'date_popup_validate'
date_popup_elements in date_popup/date_popup.module
Implementation of hook_elements().

File

date_popup/date_popup.module, line 288
A module to enable jquery calendar and time entry popups. Requires the Date API.

Code

function date_popup_validate($element, &$form_state) {
  include_once drupal_get_path('module', 'date_api') . '/date_api_elements.inc';
  date_popup_load();
  $valid_value = date_popup_input_value($element);
  if (!empty($valid_value)) {
    form_set_value($element, $valid_value, $form_state);
    return;
  }
  $error_field = implode('][', $element['#parents']);
  if (isset($element['#value']['date'])) {
    $message = NULL;
    if (!empty($element['#value']['date'])) {
      $message = t('The %label %date %time is not valid.', array(
        '%label' => $element['#title'],
        '%date' => $element['#value']['date'],
        '%time' => $element['#value']['time'],
      ));
    }
    elseif ($element['#required']) {
      $message = t('The %label date cannot be empty.', array(
        '%label' => $element['#title'],
      ));
    }
    if (!empty($message)) {
      form_set_error($error_field . '][date', $message);
    }
  }
  if (isset($element['#value']['time'])) {
    if (!empty($element['#value']['time']) && !empty($element['#value']['date'])) {

      // We already displayed a message about this, but need another message
      // here just to set the error field, so don't repeat the previous
      // message.
      $message = t('Please check the %label values.', array(
        '%label' => $element['#title'],
      ));
    }
    elseif ($element['#required']) {
      $message = t('The %label time cannot be empty.', array(
        '%label' => $element['#title'],
      ));
    }
    if (!empty($message)) {
      form_set_error($error_field . '][time', $message);
    }
  }
  form_set_value($element, NULL, $form_state);
}