You are here

function _honeypot_time_restriction_validate in Honeypot 6

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

Validate honeypot's time restriction field.

1 string reference to '_honeypot_time_restriction_validate'
honeypot_add_form_protection in ./honeypot.module
Form builder function to add different types of protection to forms.

File

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

Code

function _honeypot_time_restriction_validate($element, &$form_state) {

  // Don't do anything if the triggering element is a preview button.
  if ($form_state['triggering_element']['#value'] == t('Preview')) {
    return;
  }

  // Get the time value.
  $honeypot_time = $form_state['values']['honeypot_time'];

  // Get the honeypot_time_limit.
  $time_limit = honeypot_get_time_limit($form_state['values']);

  // Make sure current time - (time_limit + form time value) is greater than 0.
  // If not, throw an error.
  if (time() < $honeypot_time + $time_limit) {
    _honeypot_log($form_state['values']['form_id'], 'honeypot_time');

    // Get the time limit again, since it increases after first failure.
    $time_limit = honeypot_get_time_limit($form_state['values']);
    $form_state['values']['honeypot_time'] = time();
    form_set_error('', t('There was a problem with your form submission. Please wait @limit seconds and try again.', array(
      '@limit' => $time_limit,
    )));
  }
}