Time field does not update when showing a form preview, or returning a form error. Instead, the time field remains the same as the first creation of the form.

Line #223 of honeypot.module should update the field time, but it is not functioning correctly in this situation.
$form_state['values']['honeypot_time'] = time();

I have tried to figure out how to update the value, but I cannot. Please help with this.

Comments

Sepero’s picture

I have tried using both of the following without success.

form_set_value($form, $time_now, $form_state);
$form['#value'] = $time_now;

(I think that there is a typo in the validation function definition, and that $form should actually be named as $element. So that is how I am trying to use it in the above code.)
Line #211 of honeypot.module
function _honeypot_time_restriction_validate($form, &$form_state) {
Should possibly be written as this?
function _honeypot_time_restriction_validate($element, &$form_state) {

Sepero’s picture

Is the time field properly updating on previews using Drupal 7 or 8?

geerlingguy’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

I'll try taking a look at this. I don't think I've ever tested form previews—this should definitely be added to automated testing!

geerlingguy’s picture

Status: Active » Needs review
StatusFileSize
new653 bytes

I've looked into this further, and I think the best solution would be to make it so form submissions that are triggered by the 'Preview' button are not validated via Honeypot. Additionally, the timestamp that Honeypot generates should remain the same as when the form was originally built, because this value is supposed to simply restrict bots that complete the form too quickly from submitting the form; if someone is previewing the form and taking X seconds to do so, that's equivalent in my mind to making sure they take X seconds to simply fill out the form.

Attached patch changes $form to $element (thanks for catching that!), and says 'if someone is previewing the form/node, don't do any timestamp validation.'

geerlingguy’s picture

Issue tags: +Needs tests

I also need to write a test that checks to make sure the timestamp validation doesn't run if a user clicks 'Preview'.

geerlingguy’s picture

I've tested the above patch in D8, and it works as well. However, I can't do tests until #2111163: Can't Preview comments: Call to a member function id() on a non-object in comment.module, line 1371 has been fixed, because comment form previewing seems to be broken :(

geerlingguy’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Issue summary: View changes
StatusFileSize
new5.85 KB

Okay, attaching what I hope will be the final patch for D8 here... I had to fix some other problems caused by failing to stay on top of HEAD for a month or two :)

geerlingguy’s picture

Title: Time not updating on preview or form error » Don't run Honeypot checks on form previews

Updated title for clarity.

Status: Needs review » Needs work

The last submitted patch, 7: honeypot.preview-fix.2036501-7.patch, failed testing.

geerlingguy’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.33 KB

D7 backport of patch from #7 attached. Hopefully this gets a green light; my local D7 testing environment is borked, and D7 testbot should be quicker :)

Status: Needs review » Needs work

The last submitted patch, 10: honeypot.preview-fix.2036501-9.patch, failed testing.

geerlingguy’s picture

StatusFileSize
new2.32 KB

Let's try this again...

geerlingguy’s picture

Status: Needs work » Needs review
geerlingguy’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

Ready to be ported to D6 (with no tests, of course!)... here are the commits for:

geerlingguy’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new653 bytes

Patch attached.

geerlingguy’s picture

Status: Needs review » Fixed

All is well. Thanks to everyone who participated in this issue!

D6 commit: http://drupalcode.org/project/honeypot.git/commit/a774a1d

Status: Fixed » Needs work

The last submitted patch, 15: honeypot.preview-fix.2036501-15.patch, failed testing.

geerlingguy’s picture

Status: Needs work » Fixed

Bad testbot.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.