You are here

function spamicide_validate in Spamicide 6

Same name and namespace in other branches
  1. 8 spamicide.module \spamicide_validate()
  2. 5 spamicide.module \spamicide_validate()
  3. 7 spamicide.module \spamicide_validate()

Implementation of hook_validate

Parameters

$form_values:

Return value

none

1 string reference to 'spamicide_validate'
spamicide_form_alter in ./spamicide.module
Implementation of hook_form_alter

File

./spamicide.module, line 352
This module provides yet another tool to eliminate spam.

Code

function spamicide_validate($form, &$form_state) {
  $form_id = $form_state['values']['form_id'];
  $spamicide_field = _spamicide_get_field($form_id);
  if (!$spamicide_field) {
    return;
  }
  elseif (empty($form_state['values'][$spamicide_field])) {
    return;
  }
  else {

    // update attempt counter
    variable_set('spamicide_attempt_counter', variable_get('spamicide_attempt_counter', 0) + 1);

    // log to watchdog if needed
    if (variable_get('spamicide_log_attempts', TRUE)) {
      watchdog('Spamicide', '%form_id post blocked by Spamicide module: their IP address is "%ipaddress".', array(
        '%form_id' => $form_id,
        '%ipaddress' => ip_address(),
      ), WATCHDOG_NOTICE);
    }

    // If Spamicide was on a login form: stop validating, quit the current request
    // and forward to the current page (like a reload) to prevent logging in.
    // We do that because the log in procedure, which happens after
    // spamicide_validate(), does not check error conditions of extra form
    // elements like the Spamicide.
    if ($form_id == 'user_login' || $form_id == 'user_login_block') {
      drupal_goto($_GET['q']);
    }
    else {
      drupal_goto($form_state['values']['destination']);
    }
  }
}