diff --git a/honeypot.module b/honeypot.module index 83e45ca..14b8f8b 100644 --- a/honeypot.module +++ b/honeypot.module @@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Component\Utility\Crypt; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Component\Utility\Random; /** * Implements hook_help(). @@ -154,7 +155,7 @@ function honeypot_add_form_protection(&$form, FormStateInterface $form_state, ar ], ], '#type' => 'textfield', - '#title' => t('Leave this field blank'), + '#title' => _honeypot_get_field_title(), '#size' => 20, '#weight' => 100, '#attributes' => ['autocomplete' => 'off'], @@ -266,6 +267,19 @@ function _honeypot_log($form_id, $type) { } } +/** + * Generate a string that looks like a word (letters only, alternating consonants and vowels). + * + * @param int $length + * The desired word length. + * + * @return string + */ +function _honeypot_get_field_title() { + $random = new Random(); + return $random->word(mt_rand(4, 15)); +} + /** * Look up the time limit for the current user. *