Honeypot Technique: Blocking Spam

If you have forms on your website, you may encounter spam bots that submit forms. I have encountered this issue in my job. When a spam bot encounters a form, it will complete all input fields. Therefore, we can defeat the spam bots by creating an hidden input field then checking if this input field contains any characters.

  1. HTML: Setup a form with a hidden input
<form  action="yourController.php" method="post">
<input type='text'>
<input type='text' class="hidden">

2. CSS: hide input

display: none;

3. JavaScript: Check if the hidden form has no characters in it using jQuery

if($('.hidden').val().length === 0) {
// send form

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store