Quantcast
Viewing all articles
Browse latest Browse all 8

Stop form spam with a hidden field

  • 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
}

The post Stop form spam with a hidden field appeared first on codexguru.


Viewing all articles
Browse latest Browse all 8

Trending Articles