Skip to content
Snippets Groups Projects
Commit e062c07a authored by Jeff Geerling's avatar Jeff Geerling Committed by Jeff Geerling
Browse files

Issue #2820400 by Fabianx, geerlingguy: Add possibility to use JS on cached pages

parent 851532fe
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,9 @@ function honeypot_admin_form($form, &$form_state) {
'#description' => t('Enable Honeypot protection for ALL forms on this site (it is best to only enable Honeypot for the forms you need below).'),
'#default_value' => variable_get('honeypot_protect_all_forms', 0),
);
$form['configuration']['honeypot_protect_all_forms']['#description'] .= '<br />' . t('<strong>Page caching will be disabled on any page where a form is present if the Honeypot time limit is not set to 0.</strong>');
if (!variable_get('honeypot_use_js_for_cached_pages', FALSE)) {
$form['configuration']['honeypot_protect_all_forms']['#description'] .= '<br />' . t('<strong>Page caching will be disabled on any page where a form is present if the Honeypot time limit is not set to 0.</strong>');
}
$form['configuration']['honeypot_log'] = array(
'#type' => 'checkbox',
'#title' => t('Log blocked form submissions'),
......@@ -53,7 +55,7 @@ function honeypot_admin_form($form, &$form_state) {
$form['configuration']['honeypot_use_js_for_cached_pages'] = array(
'#type' => 'checkbox',
'#title' => t('Use Javascript protection for cacheable pages. (experimental)'),
'#description' => t('Uses a Javascript implementation to avoid disabling of Page caching.'),
'#description' => t('Uses Javascript to preserve Page caching.'),
'#default_value' => variable_get('honeypot_use_js_for_cached_pages', FALSE),
'#states' => array(
// Hide this when time limit is disabled.
......@@ -62,7 +64,7 @@ function honeypot_admin_form($form, &$form_state) {
),
),
);
$form['configuration']['honeypot_use_js_for_cached_pages']['#description'] .= '<br />' . t('<strong>Warning: Users that have javascript disabled will need to confirm their form submission on the next page - if the honeypot enabled form is on a cacheable page.</strong>');
$form['configuration']['honeypot_use_js_for_cached_pages']['#description'] .= '<br />' . t('<strong>Warning: Users who have javascript disabled will need to confirm their form submission on the next page (if the Honeypot-enabled form is on a cacheable page).</strong>');
// Honeypot Enabled forms.
$form['enabled_forms'] = array(
......
......@@ -330,18 +330,19 @@ function _honeypot_time_restriction_validate(&$element, &$form_state) {
$honeypot_time = FALSE;
// Is this a javascript submission?
// Update the honeypot_time for JS requests and get the $honeypot_time value.
if (strpos($form_state['values']['honeypot_time'], 'js_token:') === 0) {
$interval = _honeypot_get_interval_from_signed_js_value($form_state['values']['honeypot_time']);
if ($interval) {
// Set correct values for below validation.
// Set correct value for timestamp validation.
$honeypot_time = REQUEST_TIME - $interval;
// Update form_state and element values.
// Update form_state and element values so they're correct.
$form_state['values']['honeypot_time'] = honeypot_get_signed_timestamp($honeypot_time);
$element['#value'] = $form_state['values']['honeypot_time'];
}
}
// Otherwise just get the $honeypot_time value.
else {
// Get the time value.
$honeypot_time = honeypot_get_time_from_signed_timestamp($form_state['values']['honeypot_time']);
......@@ -356,7 +357,7 @@ function _honeypot_time_restriction_validate(&$element, &$form_state) {
_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']);
// Ensure to update both $form_state and the $element value.
// Update the honeypot_time value in the form state and element.
$form_state['values']['honeypot_time'] = honeypot_get_signed_timestamp(REQUEST_TIME);
$element['#value'] = $form_state['values']['honeypot_time'];
form_set_error('', t('There was a problem with your form submission. Please wait @limit seconds and try again.', array('@limit' => $time_limit)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment