Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
The project page states that honeypot_add_form_protection()
can be called inside your form builder function. This does not seem to be the case. The function references $form['form_id']['#value']
which does not exist until after the form has been built.
It seems you have to use hook_form_alter
to avoid errors. Not sure if this an error in the code or the documentation.
Comment | File | Size | Author |
---|---|---|---|
#4 | 1937328-4-honeypot-add-protection-fix.patch | 1.13 KB | geerlingguy |
Comments
Comment #1
geerlingguy CreditAttribution: geerlingguy commentedIt's probably an error in the documentation; I'm assuming I meant in a hook_form_alter(). But it would be convenient if you could call that in either the form builder or a form alter, so I'll leave this issue open to see if that would be easy to make work.
Comment #2
michaellenahan CreditAttribution: michaellenahan commented@geerlingguy - thank you for this excellent module.
Adding the honeypot code in my form build function works just fine for me.
However as @gigabates points out, when a form is being built it doesn't have a form_id yet.
As a result we get this error notice after adding honeypot protection to the form build function of a custom-coded form.
Can I suggest something like this in honeypot.module to prevent the notice:
Another small thing, can I suggest adding a note to the README, something like this:
I know it should be obvious, but a note like this would be helpful for dummies like me :)
Comment #3
geerlingguy CreditAttribution: geerlingguy commentedThe README suggestion is a very good suggestion indeed; you're not the first person who has been stymied by this behavior!
I think I may just pass through a null form ID or something for the invoke hook... We'll see. I'll try to get this fixed tomorrow, one way or another.
Comment #4
geerlingguy CreditAttribution: geerlingguy commentedThis actually requires a slight API change; in the honeypot API documentation, I say that the entire $form array is passed to modules implementing
hook_honeypot_add_form_protection()
, but until now, that was false—in some cases, I passed the Form ID, and in other cases, NULL.So, as long as this patch comes back green from the testbot, I'm going to commit this fix (which includes the README suggestions above), and add a note that this introduces a slight API change (to make the API behave as the documentation suggests), then I'll port to D6 and D8.
Comment #5
geerlingguy CreditAttribution: geerlingguy commentedCommit: http://drupalcode.org/project/honeypot.git/commit/471a52e
I'm going to fix this next in 6.x, then 8.x.
Comment #6
geerlingguy CreditAttribution: geerlingguy commentedD6: http://drupalcode.org/project/honeypot.git/commit/f27021a
D8: http://drupalcode.org/project/honeypot.git/commit/c35e958
Simple enough!
Comment #7
michaellenahan CreditAttribution: michaellenahan commentedThanks. I can confirm that the D7 dev release fixes the error for me!
Comment #8
geerlingguy CreditAttribution: geerlingguy commentedUpdating title to reflect the error that appears in logs (for easier discovery of this issue via search).