Captcha Image Validation
CAPTCHA is a type of response test from the server to control the spam bots or automated activities; to check whether the response is produced by person. This CAPTCHA technique requires the user to complete the simple test and used in many web forms to control the spam bots out from the webpage requires the CAPTCHA form validation. Hence the below code is developed to validate or verify the user given CAPTCHA value by comparing the server generated CAPTCHA
Javascript Code to Verify CAPTCHA
//Validate the Recaptcha' Before continuing with POST ACTION
function validateCaptcha()
{
challengeField = $("input#recaptcha_challenge_field").val();
responseField = $("input#recaptcha_response_field").val();
var html = $.ajax({
type: "POST",
url: "../php/validateform.php",
data: "form=signup&recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
async: false
}).responseText;
//console.log( html );
if(html == "success") {
//Add the Action to the Form
$("form").attr("action", "../php/db-process-form.php");
$("#submit").attr("value", "Submit");
//Indicate a Successful Captcha
$("#captcha-status").html("<p class="green bold">Success! Thanks you may now proceed.</p>");
} else {
$("#captcha-status").html("<p class="red bold">The security code you entered did not match. Please try again.</p>");
Recaptcha.reload();
}
}