Page 1 of 1

Honeypot UDT with FormBuilder – form not submitting

Posted: Thu Jun 29, 2017 1:07 pm
by 10010110
So, I have a UDT with the following code:

Code: Select all

if (isset($_POST['subject']) && !empty($_POST['subject'])) {
  if(isset($_POST['form_type'])) {$formtype = '('.$_POST['form_type'].')';}
  if(isset($_SERVER['REMOTE_ADDR'])) {$remote_ip = 'IP: '.$_SERVER['REMOTE_ADDR'];}
	audit('', "HOTBOT", "Bad ass spam attempt! $formtype, $remote_ip");
	exit('Sorry, the form cannot be processed like this.');
}
And in my FormBuilder template I have hard-coded this:

Code: Select all

<label>(Leave this field as is.) <input name="subject" type="text" /></label>
<input type="hidden" name="form_type" value="Contact form" />
In the “Form Submission” tab in FormBuilder admin under “User defined tag to call during form validation” I’ve selected the UDT.

The problem is now that when I enter my info (and leave the honeypot field blank, of course), it just reloads the page with all fields still filled out but doesn’t send it on submission. If I fill the honeypot field, it correctly displays the exit message. I don’t get any errors (not even in my error logs), as far as I can see. Can you spot any issue with my code?

[edit]I tried it on another site and upon form submission the form’s error message container is actually loaded but without any message in it. ??? [/edit]

Re: Honeypot UDT with FormBuilder – form not submitting

Posted: Thu Jun 29, 2017 5:16 pm
by Rolf

Re: Honeypot UDT with FormBuilder – form not submitting

Posted: Thu Jun 29, 2017 6:37 pm
by velden
Of course I like Rolf's solution the best O0 but in case of the UDT I guess you should read the help. I think it expects a return value (array?).

Re: Honeypot UDT with FormBuilder – form not submitting

Posted: Thu Jun 29, 2017 7:07 pm
by 10010110
Thanks, Rolf. Yeah, I came across that article already but I wanted to have a universal copy/paste solution without having to add a field to every form. And this UDT solution used to work but it seemed like spammers got around it at some point and I experimented with it, thinking I found a solution but asserted just now that it doesn’t.

velden, the UDT isn’t supposed to return anything if the input is valid. It’s only supposed to exit if the honeypot field is filled out.

Re: Honeypot UDT with FormBuilder – form not submitting

Posted: Thu Jun 29, 2017 7:46 pm
by velden
10010110 wrote:velden, the UDT isn’t supposed to return anything if the input is valid. It’s only supposed to exit if the honeypot field is filled out.
Better read the help:
Validation UDT. Set this for a form, and the UDT will receive all of the form's human-readable results. The UDT should do whatever validation it wants, and return an array with the first value being true or false (indication whether the form validates), and the second value being error messages (if any).

Re: Honeypot UDT with FormBuilder – form not submitting

Posted: Fri Jun 30, 2017 8:53 am
by 10010110
Thanks, velden, adding "return array(true);” appears to work. But where did you find that info? I can’t find it in https://docs.cmsmadesimple.org/tags/use ... ting-a-udt . And I also don’t see any help in the UDT admin (like the module help).

Re: Honeypot UDT with FormBuilder – form not submitting

Posted: Fri Jun 30, 2017 9:30 am
by velden
Ah, it has nothing to do with the UDT actually. It's the return value that FormBuilder expects. So it's in the help of FormBuilder.

Re: Honeypot UDT with FormBuilder – form not submitting

Posted: Fri Jun 30, 2017 9:33 am
by 10010110
Ah, OK. Thank you very much. :)