Simple Captcha : Form Validation with AJAX

Captcha validation or code that serves to avoid the spam. Spammers work automatically using comment spam engines to find the form or contact form or other forms on the web. Then they fill out the form with information on trash / not useful for most people or we often call it SPAM. To ban (cease-and desist) were created captcha spam attacks, a code manually inputted by the user to indicate that the user is not a spammer but a human.There are so many types of captcha that has been created, ranging from simple to complete, and some even complete with the sound (audio). But the problem is how captcha is working? Here, we discuss how a simple captcha work. Captcha code consists of numbers and letters, without the image. First, create a file named captcha.php, then type the code below:Explaination:

The second step is to make the AJAX engine (validasi.js) for the validation code you submit. The following code:var xmlHttp;function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”); } catch (e) { xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”); } } return xmlHttp;}function validasi(actionstr) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert (“Browser does not support HTTP Request”) return false; } var actionstr; //addproducts param values list specification if(actionstr == “checkCode”){ var inputCode = document.getElementById(‘code’).value; var captchaCode = document.getElementById(‘captcha’).value; if(inputCode != captchaCode){ alert(‘The code you entered is wrong, Please Try Again’); document.getElementById(‘code’).style.background = ‘red’; document.getElementById(‘code’).value = ”; document.getElementById(‘code’).focus(); return false; }else{ alert(‘Success !’); document.getElementById(‘result’)[removed] = ‘Success !’; document.getElementById(‘code’).value = ”; document.getelementById(‘form-captcha’).style.visibility = ‘hidden’; document.getelementById(‘form-captcha’).style.display = ‘none’; } }}The last step is the implementation of the captcha in index.php. Here’s the code:

Enter Code :



 

Read this article in Indonesian language here.

Lukmanul Hakim is a web programmer and graphic designer, who interested in internet promoting and online marketing.

You can leave a response, or trackback from your own site.

Leave a Reply

Free WordPress Themes Design by New WordPress Themes | Thanks to Insurance and Home Insurance