You are here

function antibot_form_validation in Antibot 7

Same name and namespace in other branches
  1. 8 antibot.module \antibot_form_validation()

Validation to Antibot-protected forms.

See also

antibot_protect_form()

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 183
Attempt to prevent robotic form submissions and spam.

Code

function antibot_form_validation($form, &$form_state) {

  // Check if a key was provided in the form.
  if (!empty($form['#antibot_key'])) {

    // Views exposed forms will initially load and submit without the key.
    if ($form['#form_id'] == 'views_exposed_form' && empty($form_state['input']['antibot_key'])) {

      // We must allow this.
      return;
    }

    // Allow programmatic form submissions.
    if ($form_state['programmed'] == TRUE) {
      return;
    }

    // Validate the key.
    if (empty($form_state['input']['antibot_key']) || $form['#antibot_key'] != $form_state['input']['antibot_key']) {

      // Prevent the form from submitting.
      form_set_error('', t('Submission failed. Please reload the page and try again.'));
    }
  }
}