You are here

function event_validate_form_date in Event 5.2

Same name and namespace in other branches
  1. 5 event.module \event_validate_form_date()

Validates the start and end times in a node form submission.

  • Changes 24 hour time to 12 hour time (if the module is configured to do this).

    • Adjusts times for time zone offsets.

Parameters

$form_values The submitted data.:

$date The name of the event's date ('start' or 'end') to validate and set.:

Related topics

1 call to event_validate_form_date()
event_form_validate in ./event.module

File

./event.module, line 1595

Code

function event_validate_form_date($form_values, $date) {
  $prefix = $date . '_';
  if (!module_exists('jscalendar')) {
    if (isset($form_values[$prefix . 'year']) && !is_numeric($form_values[$prefix . 'year'])) {
      form_set_error($prefix . 'year', t('The year has to be a number.'));
    }
    if (isset($form_values[$prefix . 'year']) && ($form_values[$prefix . 'year'] < 1000 || $form_values[$prefix . 'year'] > 9999)) {
      form_set_error($prefix . 'year', t("Only years from 1000 to 9999 are supported."));
    }
    if (isset($form_values[$prefix . 'month']) && $form_values[$prefix . 'month'] > 12) {
      form_set_error($prefix . 'month', t("A year has only 12 months in the Gregorian calendar."));
    }
    if (isset($form_values[$prefix . 'day']) && $form_values[$prefix . 'day'] > 31) {
      form_set_error($prefix . 'day', t("Months with more than 31 day don't exist."));
    }
    if (isset($form_values[$prefix . 'day']) && !is_numeric($form_values[$prefix . 'day'])) {
      form_set_error($prefix . 'day', t("A day needs to be a number."));
    }
    if (variable_get('event_ampm', '0')) {
      if (isset($form_values[$prefix . 'hour']) && $form_values[$prefix . 'hour'] > 12) {
        form_set_error($prefix . 'hour', t('There are only 12 hours in the day for the am/pm time format.'));
      }
    }
    else {
      if (isset($form_values[$prefix . 'hour']) && $form_values[$prefix . 'hour'] > 24) {
        form_set_error($prefix . 'hour', t('There are only 24 hours in the day.'));
      }
    }
    if (isset($form_values[$prefix . 'minute']) && $form_values[$prefix . 'minute'] > 60) {
      form_set_error($prefix . 'minute', t('There are only 60 minutes in the day.'));
    }
  }
}