Prevent Contact Form Spam Without CAPTCHA

Prevent Contact Form Spam Without CAPTCHA

Nowadays there is a common problem in website form is spam enquiries. Bots fill up the spam enquiries in our website via the form to get rid of this most developers use captcha or Recaptcha, But captcha or Recaptcha irritates user experience, so there is another solution is that we can solve spam enquiries by putting hidden input field in the form.

In this blog I am showing the steps of the CodeIgniter framework, you can use this technique in any language such as php,.net etc. Let’s see the following steps:

Step1:  In View file adds the hidden input field and add a form name , script code like this:

  <title>Contact Us</title> 
  <?php echo validation_errors(); ?> 
 <form name="contact_form" method="post" id="validate-form" > 
  <input type="hidden" name="_a2a2a_" value="23"> 
  <input type="text" name="name" value="" size="50" /> 
  <input type="text" name="mobile" value=""  /> 
  <h5>Email Address</h5> 
  <input type="text" name="email" value="" size="50" /> 
  <textarea name="message" > </textarea> 
  <div><input type="submit" value="Submit" /></div> 
 <script type="text/javascript"> 
 var formname = "contact_form"; 
 var fieldname = "_a2a2a_"; 
 var finalvalue = "4"; 
 var soft_sell = "document."; 
 soft_sell += formname; 
 soft_sell += "." + fieldname + ".va"; 
 eval(soft_sell + "lue='"+finalvalue+"'"); 

In the Controller file function validate the code like this:

if(isset($_POST['submit']) and (isset($_POST["_a2a2a_"])) and $_POST["_a2a2a_"] == "4" ) 
   // write the code whatever you want , send email or insert data in database; 

This concept is called Honeypot Method, it is a very useful technique to get rid of spam enquiries.