You are here

function botcha_form_alter in BOTCHA Spam Prevention 6.2

Same name and namespace in other branches
  1. 6 botcha.module \botcha_form_alter()
  2. 7 botcha.module \botcha_form_alter()
  3. 7.2 botcha.module \botcha_form_alter()

Implements hook_form_alter().

This function adds BOTCHA protection to forms for untrusted users if needed and adds BOTCHA administration links for site administrators if this option is enabled.

File

./botcha.module, line 280

Code

function botcha_form_alter(&$form, &$form_state, $form_id) {

  // @todo Replace this ugly workaround.
  // The reason is in the fact that _SESSION variables state differ on test script

  //and on this side while running simpletest tests.
  Botcha::clean();

  // Get an instance of BOTCHA special form handler.
  $botcha_form = Botcha::getForm($form_id, FALSE);

  // Add admin links functionality.
  $botcha_form
    ->addAdminLinks($form);

  // Check if it is allowed to protect.
  if ($botcha_form
    ->isEnabled()) {

    // Get a recipe book and apply all applicable recipes to the form.
    $recipebook = $botcha_form
      ->getRecipebook();
    if ($recipebook
      ->isApplicable($form, $form_state)) {
      $recipebook
        ->apply($form, $form_state);
    }
  }
}