You are here

public function CaptchaQuestionsSettingsForm::validateForm in Captcha Questions 8

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/CaptchaQuestionsSettingsForm.php, line 226

Class

CaptchaQuestionsSettingsForm
Displays the captcha_questions settings form.

Namespace

Drupal\captcha_questions\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  // If question is specified without answer, ask for answer.
  if (!empty($form_state
    ->getValue('captcha_questions_question')) && empty($form_state
    ->getValue('captcha_questions_answers'))) {
    $form_state
      ->setErrorByName('captcha_questions_answer', $this
      ->t('Please provide an answer'));
  }

  // If answer given, but no question, ask for question.
  if (empty($form_state
    ->getValue('captcha_questions_question')) && !empty($form_state
    ->getValue('captcha_questions_answers'))) {
    $form_state
      ->setErrorByName('captcha_questions_question', $this
      ->t('Please add a question'));
  }
  parent::validateForm($form, $form_state);
}