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:

<html> 
  <head> 
  <title>Contact Us</title> 
  </head> 
  <body> 
   
  <?php echo validation_errors(); ?> 
    
 <form name="contact_form" method="post" id="validate-form" > 
  <input type="hidden" name="_a2a2a_" value="23"> 
  <h5>Name</h5> 
  <input type="text" name="name" value="" size="50" /> 
   
  <h5>Mobile</h5> 
  <input type="text" name="mobile" value=""  /> 
   
  <h5>Email Address</h5> 
  <input type="text" name="email" value="" size="50" /> 
  <h5>Message</h5> 
  <textarea name="message" > </textarea> 
   
   
  <div><input type="submit" value="Submit" /></div> 
    
  </form> 
    
 <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+"'"); 
 </script> 
  </body> 
  </html> 
   


Step2:
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.

Categories: web development codeigniter

Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 25 Days

Crash : 15 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 6 Months

Fastrack : 4 Months

Crash : 2 Months

Related Blogs

Request For Demo