public function DateFilter::validateForm in Visitors 8.2
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ DateFilter.php, line 93
Class
Namespace
Drupal\visitors\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$fromvalue = $form_state
->getValue('from');
$tovalue = $form_state
->getValue('to');
$from = array();
$to = array();
$from['month'] = (int) $fromvalue
->format('m');
$from['day'] = (int) $fromvalue
->format('d');
$from['year'] = (int) $fromvalue
->format('y');
$to['month'] = (int) $tovalue
->format('m');
$to['day'] = (int) $tovalue
->format('d');
$to['year'] = (int) $tovalue
->format('y');
$error_message = $this
->t('The specified date is invalid.');
if (!checkdate($from['month'], $from['day'], $from['year'])) {
return $this
->setFormError('from', $form_state, $error_message);
}
if (!checkdate($to['month'], $to['day'], $to['year'])) {
return $this
->setFormError('to', $form_state, $error_message);
}
$from = mktime(0, 0, 0, $from['month'], $from['day'], $from['year']);
$to = mktime(23, 59, 59, $to['month'], $to['day'], $to['year']);
if ((int) $from <= 0) {
return $this
->setFormError('from', $form_state, $error_message);
}
if ((int) $to <= 0) {
return $this
->setFormError('to', $form_state, $error_message);
}
if ($from > $to) {
return $this
->setFormError('from', $form_state, $error_message);
}
}