Stop form spam with a hidden field
Sick of teh spamz? Here’s an easy way to block a lot of automated spam from your contact form.
In this mini-tutorial, we use a hidden form field to catch and block automated spammers and bots. It’s quite effective.
Step 1: HTML
Include this snippet in your contact form:
<label for="humans" class="humans">Human check: Leave this field empty</label>
<input type="text" name="humans" id="humans" class="humans" />
Step 2: CSS
Now let’s hide the field with some CSS:
.humans { display: none; }
Step 3: PHP
Everything is setup, now to catch the non-humans in the PHP script used to process the contact form, like so:
if(!empty($_POST['humans'])) {
// it's spam
} else {
// it's human
}
More form-related security techniques: