function quant_time_form_validate in Quant 6
Same name and namespace in other branches
- 7 quant.pages.inc \quant_time_form_validate()
Validate handler for quant_time_form()
File
- includes/
forms.inc, line 84 - Form-building functions
Code
function quant_time_form_validate($form, &$form_state) {
$values = $form_state['values'];
// Make sure a time option is checked
if (!$values['option']) {
form_set_error('error', t('An option must be selected'));
}
// If custom option, make sure we have both dates
if ($values['option'] == 'custom' && !($values['custom_from'] && $values['custom_to'])) {
form_set_error('option', t('You must specify both dates'));
}
else {
if ($values['option'] == 'custom') {
// Convert the times
$now = time();
$from = strtotime($values['custom_from']);
$to = strtotime($values['custom_to']);
// Make sure from date exists
if (!$from) {
form_set_error('custom_from', t('The from date must be formatted correctly %format.', array(
'%format' => '(MM/DD/YY)',
)));
}
// Make sure to date exists
if (!$to) {
form_set_error('custom_to', t('The to date must be formatted correctly %format.', array(
'%format' => '(MM/DD/YY)',
)));
}
// Make sure from is less than to
if ($from > $to) {
form_set_error('custom_from', t('The from date must be before the to date'));
}
// Make sure to date is not past current time
if ($to > $now) {
form_set_error('custom_to', t('The to date must not be past today'));
}
}
}
}