function honeypot_form_alter in Honeypot 6
Same name and namespace in other branches
- 8 honeypot.module \honeypot_form_alter()
- 7 honeypot.module \honeypot_form_alter()
- 2.0.x honeypot.module \honeypot_form_alter()
Implementation of hook_form_alter().
Add Honeypot features to forms enabled in the Honeypot admin interface.
File
- ./
honeypot.module, line 39 - Honeypot module, for deterring spam bots from completing Drupal forms.
Code
function honeypot_form_alter(&$form, &$form_state, $form_id) {
// Don't use for maintenance mode forms (install, update, etc.).
if (defined('MAINTENANCE_MODE')) {
return;
}
$unprotected_forms = array(
'user_login',
'user_login_block',
'search_form',
'search_theme_form',
'views_exposed_form',
'honeypot_admin_form',
);
// If configured to protect all forms, add protection to every form.
if (variable_get('honeypot_protect_all_forms', 0) && !in_array($form_id, $unprotected_forms)) {
// Don't protect system forms - only admins should have access, and system
// forms may be programmatically submitted by drush and other modules.
if (strpos($form_id, 'system_') === FALSE && strpos($form_id, 'search_') === FALSE && strpos($form_id, 'views_exposed_form_') === FALSE) {
honeypot_add_form_protection($form, $form_state, array(
'honeypot',
'time_restriction',
));
}
}
elseif ($forms_to_protect = honeypot_get_protected_forms()) {
foreach ($forms_to_protect as $protect_form_id) {
// For most forms, do a straight check on the form ID.
if ($form_id == $protect_form_id) {
honeypot_add_form_protection($form, $form_state, array(
'honeypot',
'time_restriction',
));
}
elseif ($protect_form_id == 'webforms' && strpos($form_id, 'webform_client_form') !== FALSE) {
honeypot_add_form_protection($form, $form_state, array(
'honeypot',
'time_restriction',
));
}
}
}
}