How to Stop Spam Form Submissions Without a CAPTCHA
By: Wil Helser
We’ve all seen it… Web form submissions with gibberish filled in the form fields. Personally, I don’t know what purpose it serves… I suspect the spam-bots think the form is a comment form or something. Whatever the case may be, it’s annoying. I’m going to show you a super simple way to stop that nonsense. All it takes is a couple lines of HTML, one line of CSS and a few lines of PHP. Easy right?
The first step is to add a form field that we’ll hide with CSS. Any regular user won’t be able to see this field, but spam-bots will see it just like any other field and will fill it out. Here’s an example:
The next step is to hide the field with CSS. Just set it to “display: none”.
Now, you just add a few lines to your form processing script to check if that field has been filled out. If it has, handle it however you want. In this example, I just tell the script to die, but you could log the IP and add it to your IP tables or anything you want really. Here’s an example of the PHP:
That’s all there is to it! I told you it was super simple. Obviously, this won’t do anything to stop spam that someone actually sits down and manually types in to your contact form, but every time I’ve implemented this on a site it’s cut the spam-bot spam down to none!


By Liana May 27, 2012 - 4:49 pm
Wil,
Thank you for posting the no spam bot form code. I have tried this several times but cannot seem to get it to “display:none” II added a new field and called it “username” but I am stuck on #2 with the css. . Where and what exactly do I place to make it display: none?. ANY help would be GREATLY appreciated.
Thank you,
Liana
By Wil Helser October 3, 2012 - 10:06 pm
Hi Liana! You want to put your field inside of a list-item and then set “display: none” on the list item, not the field itself. That’s assuming that you’re using the same markup that I’m using. If you structure your forms differently, just wrap the “username” field in some kind of element… div, span, p, whatever you use… and set “display: none” to that element. Does that help?
By Neal Ferri June 15, 2012 - 2:05 pm
Thank you so much for this easy to use script. I spent about 5 days trying to figure out how to do this. Your explanation was simple but very effective. I have little to no php experience and you were able to make my site work. THANK YOU!!!!!
By Wil Helser October 3, 2012 - 10:02 pm
Thanks for the comment Neal! Glad it helped!