function antibot_form_pre_render in Antibot 7
Pre-render callback on forms that have Antibot protection.
See also
1 string reference to 'antibot_form_pre_render'
- antibot_protect_form in ./
antibot.module - Helper function to enable Antibot protection for a given form.
File
- ./
antibot.module, line 132 - Attempt to prevent robotic form submissions and spam.
Code
function antibot_form_pre_render($form) {
// Attach the needed JavaScript to re-enable this form.
$form['antibot'] = array(
'#attached' => array(
'js' => array(
array(
'type' => 'setting',
'data' => array(
'antibot' => array(
'forms' => array(
$form['#id'] => array(
'action' => $form['#action'],
'key' => !empty($form['#antibot_key']) ? $form['#antibot_key'] : NULL,
),
),
),
),
),
drupal_get_path('module', 'antibot') . '/js/antibot.js',
),
),
);
// Change the action so the submission does not go through.
$form['#action'] = base_path() . 'antibot';
// Add a class to the form.
$form['#attributes']['class'][] = 'antibot';
// Provide a message in the event that the user does not have JavaScript.
$no_js = array(
'#theme' => 'antibot_no_js',
'#weight' => -500,
'#message' => t('You must have JavaScript enabled to use this form.'),
);
$no_js = drupal_render($no_js);
// Inject the message in to the form.
if (!isset($form['#prefix'])) {
$form['#prefix'] = '';
}
$form['#prefix'] = $no_js . $form['#prefix'];
return $form;
}