public function RiddlerSettingsForm::validateForm in Captcha Riddler 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/ RiddlerSettingsForm.php, line 184
Class
- RiddlerSettingsForm
- Displays the Riddler settings form.
Namespace
Drupal\riddler\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getTriggeringElement()['#value'] == 'Remove') {
return;
}
$values = $form_state
->getValues()['riddler'];
foreach ($values as $key => $value) {
if (empty($value['question']) && empty($value['response'])) {
unset($form_state
->getValues('riddler')['riddler'][$key]);
}
else {
if (empty($value['question'])) {
$form_state
->setError($form['riddler'][$key]['question'], $this
->t('Please add a question.'));
}
if (empty($value['response'])) {
$form_state
->setError($form['riddler'][$key]['response'], $this
->t('Please add an answer.'));
}
}
}
parent::validateForm($form, $form_state);
}