You are here

function spamicide_validate in Spamicide 8

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

Implements hook_validate().

1 string reference to 'spamicide_validate'
spamicide_form_alter in ./spamicide.module
Implements hook_form_alter().

File

./spamicide.module, line 94
Spamicide.module.

Code

function spamicide_validate(array $form, FormStateInterface &$form_state) {
  $spamicide = $form_state
    ->getValue('feed_me');
  $spamicide_settings = \Drupal::configFactory()
    ->getEditable('spamicide.settings');
  if (empty($spamicide)) {
    return;
  }
  $form_state
    ->setError($form, 'Spamicide prevent form submit');

  // Log to watchdog if needed.
  if ($spamicide_settings
    ->get('spamicide_log_attempts')) {
    $counter = $spamicide_settings
      ->get('spamicide_counter') + 1;
    $spamicide_settings
      ->set('spamicide_counter', $counter);
    $spamicide_settings
      ->save();
    \Drupal::logger('spamicide')
      ->notice(t('%form_id post blocked by Spamicide module: their IP address is "%ipaddress".', [
      '%form_id' => $form['form_id'],
      '%ipaddress' => Drupal::request()
        ->getClientIp(),
    ]));
  }
  $response = new RedirectResponse(Url::fromRoute('<current>')
    ->toString());
  $response
    ->send();
}