Closed robertgarrigos closed 4 years ago
@robertgarrigos here is the hook:
honeypot_add_form_protection(
$form,
$form_state,
array('honeypot', 'time_restriction')
);
oh thanks. missed it!
Funnily I hadn't thought of this. Might have better to implement something like captcha does.
mmmm maybe my issue wasn't clear. I believe this is not what I need. This honeypot_add_form_protection() hook is to add other types of protection to forms, but I need to protect my module's form with honeypot. I see that honeypot gets a list of forms to protect from the settings page with the function honeypot_get_protected_forms(), but cannot see a way to alter this list to add other forms. Is it?
Right. I actually see now that there is TODO note on that honeypot_get_protected_forms(): @todo - Add in API call/hook to allow modules to add to this array.
Something like this would do it, put at the end of honeypot_form_alter():
foreach (module_implements('honeypot_form_protect') as $module) {
$forms_to_protect = call_user_func($module . '_honeypot_form_protect');
foreach ($forms_to_protect as $protect_form_id) {
if ($form_id == $protect_form_id) {
honeypot_add_form_protection($form, $form_state, array('honeypot', 'time_restriction'));
}
}
}
Then, other modules could implement this hook:
function may_module_honeypot_form_protect()
{
return array(
'my_module_form',
);
}
Hi @robertgarrigos good idea! I took your idea and adapted slightly in this PR https://github.com/backdrop-contrib/honeypot/pull/30. Please give it a spin and let me know if it's ready.
Tested it and worked as expected :-) Thanks!
As far as I can see, there is no way to add form ids, to protect them, other than the ones already in settings. It would be nice to be able to hook into the module other modules from contrib modules.