function webform_validate_time in Webform 5.2
Same name and namespace in other branches
- 5 components/time.inc \webform_validate_time()
- 6.3 components/time.inc \webform_validate_time()
- 6.2 components/time.inc \webform_validate_time()
- 7.4 components/time.inc \webform_validate_time()
- 7.3 components/time.inc \webform_validate_time()
File
- components/
time.inc, line 163 - Webform module time component.
Code
function webform_validate_time($form_item) {
$form_key = $form_item['#webform_component']['form_key'];
$name = $form_item['#webform_component']['name'];
// Check if the user filled the required fields.
foreach ($form_item['#webform_component'] == '12-hour' ? array(
'hour',
'minute',
'ampm',
) : array(
'hour',
'minute',
) as $field_type) {
if (!is_numeric($form_item[$field_type]['#value']) && $form_item['#required']) {
form_set_error($form_key, t('%field field is required.', array(
'%field' => $name,
)));
return;
}
}
// Check for a valid time.
if ($form_item['hour']['#value'] !== '' || $form_item['minute']['#value'] !== '' || isset($form_item['ampm']) && $form_item['ampm']['#value'] !== '') {
if (!is_numeric($form_item['hour']['#value']) || !is_numeric($form_item['minute']['#value']) || isset($form_item['ampm']) && $form_item['ampm']['#value'] === '') {
form_set_error($form_key, t('Entered %name is not a valid time.', array(
'%name' => $name,
)));
return;
}
}
}