You are here

function honeypot_log_failure in Honeypot 8

Same name and namespace in other branches
  1. 6 honeypot.module \honeypot_log_failure()
  2. 7 honeypot.module \honeypot_log_failure()
  3. 2.0.x honeypot.module \honeypot_log_failure()

Log the failed submission with timestamp and hostname.

Parameters

string $form_id: Form ID for the rejected form submission.

string $type: String indicating the reason the submission was blocked. Allowed values:

  • honeypot: If honeypot field was filled in.
  • honeypot_time: If form was completed before the configured time limit.
1 call to honeypot_log_failure()
_honeypot_log in ./honeypot.module
Log blocked form submissions.

File

./honeypot.module, line 322
Honeypot module, for deterring spam bots from completing Drupal forms.

Code

function honeypot_log_failure($form_id, $type) {
  $account = \Drupal::currentUser();
  $uid = $account
    ->id();

  // Log failed submissions.
  \Drupal::database()
    ->insert('honeypot_user')
    ->fields([
    'uid' => $uid,
    'hostname' => Drupal::request()
      ->getClientIp(),
    'timestamp' => \Drupal::time()
      ->getRequestTime(),
  ])
    ->execute();

  // Allow other modules to react to honeypot rejections.
  // TODO - Only accepts two args.
  \Drupal::moduleHandler()
    ->invokeAll('honeypot_reject', [
    $form_id,
    $uid,
    $type,
  ]);
}