You are here

function antibot_protect_form in Antibot 7

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

Helper function to enable Antibot protection for a given form.

Parameters

array &$form: The form to enable Antibot protection on.

1 call to antibot_protect_form()
antibot_form_alter in ./antibot.module
Implements hook_form_alter().

File

./antibot.module, line 77
Attempt to prevent robotic form submissions and spam.

Code

function antibot_protect_form(array &$form) {

  // Ensure the form has an ID set.
  if (!empty($form['#form_id'])) {

    // Generate a key for this form.
    $key = md5($form['#form_id']);

    // Store the key in the form.
    $form['#antibot_key'] = $key;

    // Add a hidden value which will receive the key via JS.
    // The point of this is to add an additonal layer of protection for remotely
    // POSTed forms. Since the key will not be present in that scenario, the
    // remote post will fail.
    $form['antibot_key'] = array(
      '#type' => 'hidden',
      '#value' => '',
    );

    // Add validation for the key.
    $form['#validate'][] = 'antibot_form_validation';
  }

  // Add a pre-render to activate antibot.
  $form['#pre_render'][] = 'antibot_form_pre_render';
}