You are here

function office_hours_select_validate in Office Hours 6.2

Same name and namespace in other branches
  1. 6 office_hours.elements.inc \office_hours_select_validate()

Validate the hours selector element.

1 string reference to 'office_hours_select_validate'
_office_hours_elements in ./office_hours.elements.inc
Implementation of hook_elements().

File

./office_hours.elements.inc, line 137
office_hours.elements.inc Office hours form elements and their theming and validation. This file is only included during the edit process to reduce memory usage.

Code

function office_hours_select_validate($element, &$form_state) {

  //$hour = $element['#value']['hours'];
  $hour = $element['hours']['#value'];
  $minutes = $element['minutes']['#value'] == 0 ? '00' : $element['minutes']['#value'];

  //$minutes = ($element['#value']['minutes'] == 0) ? '00' : $element['#value']['minutes'];
  if ($element['#hoursformat']) {
    if ($element['ampm']['#value'] == 'pm' && $hour < 12) {
      $hour += 12;
    }
    if ($element['ampm']['#value'] == 'am' && $hour == 12) {
      $hour -= 12;
    }
  }
  if ($hour != '' && $minutes != '') {
    form_set_value($element, (string) $hour . $minutes, $form_state);
  }
  else {
    form_set_value($element, '', $form_state);
  }
  if ($hour < 0 || $hour > 23) {
    form_error($element, t('Hours should be between 0 and 23.'));
  }
  if ($minutes < 0 || $minutes > 59) {
    form_error($element, t('Minutes should be between 0 and 59.'));
  }
}