Every public form on the internet is eventually found by bots. The first sign is usually the inbox: enquiries in languages nobody in the office speaks, links to sites you would rather not name, the same message forty times overnight. The quick fix is a CAPTCHA, the box of traffic lights or wavy letters. It works, partly, and it moves the cost of your spam problem onto every genuine customer who wants to contact you.
There is a better order to do things in. Most form spam comes from cheap scripts, and cheap scripts can be caught by checks a real visitor never notices. This post explains the three we use, with the code we wrote for the IIMM Cochin website as the example. Its enquiry, course application and membership forms had been found by bots, and every junk submission also landed in the office inbox.
Know which kind of spam you have
Two very different things arrive through a contact form, and they need different answers.
- Scripted spam: a program finds the form, fills every field it can see and posts it, thousands of times, across thousands of sites. It doesn't read your page and it doesn't wait.
- Human spam: a person, often paid per message, pastes a pitch for SEO services or a "partnership" into your form. It reads like an enquiry because a person wrote it.
The checks below are built for the first kind. Nothing invisible stops the second, because to your website it looks exactly like a customer. A CAPTCHA doesn't stop it either: the person sending it can solve the puzzle as easily as your customer can.
Check 1: a field only a bot will fill
A honeypot is an extra text field that people can't see and scripts can. A script that fills every input fills this one too, and any submission with something in it is thrown away.
Two details decide whether a honeypot works or causes trouble. First, it must be an ordinary text field hidden with CSS, not a field of type "hidden". Many scripts skip hidden inputs and fill anything that looks like a real field. On IIMM's forms the trap is named "website_url", because bots are drawn to anything that looks like a link field.
Second, it must stay out of the way of real people who don't use a mouse and a screen. A field that is only moved off-screen can still be reached with the Tab key, read out by a screen reader, or filled in by the browser's autofill, and then a genuine enquiry is binned without anyone knowing. The IIMM field is taken out of the tab order, hidden from assistive technology and has autofill switched off. Its label reads "Leave this field empty", as a last line of defence.
Check 2: nobody fills in a form in two seconds
Scripts are fast. They load the page and post the form in the same moment. People are slow: even the shortest enquiry form takes a few seconds to read and type into.
So the form records when the page was loaded, in an encrypted hidden field the visitor can't alter, and the server checks the gap when the form comes back. On IIMM's forms, anything posted within two seconds is treated as automated. The limit is deliberately low. Someone using autofill can be quick, and the aim is to catch scripts, not to second-guess people.
The check is built to fail open. If the timestamp is missing or can't be read, for example because the page was served from an old cached copy, the submission goes through and the other checks still apply. Losing a real enquiry is worse than letting one piece of spam in.
Check 3: a limit on how often anyone can post
The third check doesn't try to tell people from programs. It caps how many times a form can be submitted from one address in a minute. IIMM's forms allow five a minute, which no genuine visitor needs and which stops a script from posting the same form hundreds of times. Laravel, the framework the site is built on, has rate limiting built in, so this is one line of configuration rather than a project.
It is also the safety net for the other two checks. A script clever enough to leave the honeypot empty and wait a few seconds still can't flood you.
Don't tell the bot it failed
When a submission trips a check, the IIMM site shows exactly the same thank-you message a genuine visitor sees. Behind the scenes the submission is dropped and logged with the reason, the form and the address it came from, so the team can see what is being caught.
An error message would tell whoever wrote the script which check caught it, and invite them to try variations until something gets through. A normal-looking success tells them nothing.
What these checks won't catch
- People typing pitches by hand. A filter on messages packed with links helps, but some will always get through.
- Bots that drive a real browser, wait, and skip hidden fields. They cost more to run, so they are less common against small business sites, but they exist.
- Abuse spread across many addresses, which slips under a per-address limit.
If junk still gets through once the quiet checks are in place, that is the time to add something stronger, and not before.
When a CAPTCHA is worth it, and which kind
The W3C makes the same argument in its note on the inaccessibility of CAPTCHA, last updated in December 2021 by its accessibility working group. Image and audio puzzles shut out people who are blind, deaf, dyslexic or have cognitive disabilities, and the note recommends the least demanding check that works: "if a honeypot suffices, use a honeypot until evidence of robotic attacks dictates something else". It also admits that there is still no single, ideal solution.
If you do need more, the current options rarely show a puzzle:
- Google reCAPTCHA v3 shows nothing at all. It gives each request a score from 0.0 (very likely a bot) to 1.0 (very likely a person). Google suggests starting with a threshold of 0.5 and watching your own traffic before you act on the scores. If you hide its badge, Google requires the text "This site is protected by reCAPTCHA" to appear in the form instead.
- Cloudflare Turnstile works on any site, whether or not it uses Cloudflare's network. It tries to avoid challenges altogether, although its recommended mode may show a checkbox to visitors it is unsure about.
Both put another company's script on your page and send it information about your visitors. Mention them in your privacy policy, and if you have visitors in the EU, check whether they need consent first.
Where to start
- Add a honeypot field and a time check to every public form, and drop what they catch quietly.
- Put a rate limit on each form.
- Log what gets caught for a few weeks, so you know what you are actually dealing with.
- Only then decide whether you need a third-party check, and pick one that doesn't hand your customers a puzzle.
A spam filter is one of the smaller jobs in a website build, but it decides whether the enquiry form is something the office trusts or something it learns to ignore. If your forms are drowning in junk, our web development team can add these checks to an existing site as well as a new one.