You are here

function webform_validate_time in Webform 6.3

Same name and namespace in other branches
  1. 5.2 components/time.inc \webform_validate_time()
  2. 5 components/time.inc \webform_validate_time()
  3. 6.2 components/time.inc \webform_validate_time()
  4. 7.4 components/time.inc \webform_validate_time()
  5. 7.3 components/time.inc \webform_validate_time()
1 string reference to 'webform_validate_time'
_webform_render_time in components/time.inc
Implements _webform_render_component().

File

components/time.inc, line 257
Webform module time component.

Code

function webform_validate_time($element, $form_state) {
  $form_key = $element['#webform_component']['form_key'];
  $name = $element['#webform_component']['name'];

  // Check if the user filled the required fields.
  foreach ($element['#hourformat'] == '12-hour' ? array(
    'hour',
    'minute',
    'ampm',
  ) : array(
    'hour',
    'minute',
  ) as $field_type) {
    if ($element[$field_type]['#value'] === '' && $element['#required']) {
      form_error($element, t('%field field is required.', array(
        '%field' => $name,
      )));
      return;
    }
  }

  // Check for a valid time.
  if ($element['hour']['#value'] !== '' || $element['minute']['#value'] !== '') {
    if (!is_numeric($element['hour']['#value']) || !is_numeric($element['minute']['#value']) || isset($element['ampm']) && $element['ampm']['#value'] === '') {
      form_error($element, t('Entered %name is not a valid time.', array(
        '%name' => $name,
      )));
      return;
    }
  }
}