function antibot_form_validation in Antibot 8
Same name and namespace in other branches
- 7 antibot.module \antibot_form_validation()
Validation callback for Antibot-enabled forms.
See also
1 string reference to 'antibot_form_validation'
- antibot_protect_form in ./
antibot.module - Helper function to enable Antibot protection for a given form.
File
- ./
antibot.module, line 144 - Implements the antibot module.
Code
function antibot_form_validation($form, FormStateInterface $form_state) {
// Stop validation if the form was submitted programmatically.
if ($form_state
->isProgrammed()) {
return;
}
// Get the user input.
$input = $form_state
->getUserInput();
// Extract the submitted key.
$submitted_key = isset($input['antibot_key']) ? $input['antibot_key'] : NULL;
// Views exposed forms will initially load and submit without the key.
if ($form['#form_id'] == 'views_exposed_form' && $submitted_key === NULL) {
// We must allow this.
return;
}
// Check if the key is missing or is not a match.
if (!$submitted_key || $submitted_key != $form['#antibot_key']) {
$form_state
->setErrorByName('', t('Submission failed. Please reload the page, ensure JavaScript is enabled and try again.'));
}
}