You are here

public function RegcodeAdminCreateForm::validateDate in Registration codes 8

Ensures a blank date validates.

File

src/Form/RegcodeAdminCreateForm.php, line 180

Class

RegcodeAdminCreateForm
Form for creation of registration codes.

Namespace

Drupal\regcode\Form

Code

public function validateDate(array &$element, FormStateInterface $form_state) {
  if (isset($element['#value']) && !empty($element['#value'])) {
    $date = strtotime($element['#value']);
    $day = date('d', $date);
    $month = date('m', $date);
    $year = date('Y', $date);
    if (!checkdate($month, $day, $year)) {
      $form_state
        ->setError($element, $this
        ->t('The specified date is invalid.'));
    }
  }
  return $element;
}