Hi all,
I would like to ask if anyone could help me about AJAX validation error message with CAPTCHA (secureimage) - At the moment the error message display at processForm.php, IF user entered a wrong code.
But what I would like do to is; the error message will POP UP on the same page on checkForm.php instead of the next page. I managed to show the error message if user did not fill the code field but not able to show the error message IF user entered the code incorrect.
Basically I have forms (checkForm.php, processForm.php & thankyou.php) - I have all the standard check error / validation which is in JavaScript e.g.
checkForm.php
<script type="text/javascript">
$(document).ready(function(){
$('#btn_submit').click(function() {
var error_num = 0;
var error_mesg = "";
$('[name=name]').parent().removeClass('error');
if($('[name=name]').val()==""){
error_num++;
error_mesg += "Please enter your name\n";
..
..
..
$('[name=name]').parent().addClass('error');$('[name=captcha_code]').parent().removeClass('error');
if($('[name=captcha_code]').val()==""){
error_num++;
error_mesg += "Please enter the image verification\n";
$('[name=captcha_code]').parent().addClass('error');
}
if(error_num>0){
alert(error_mesg);
}else if(error_num==0){
//alert("in");
$('#present_form').submit();
//document.present_form.submit();
}
return false;
});
});
</script>
<!--And the rest are just HTML code-->
..
..
<tr>
<td width="20%">Name</td>
<td width="80%"><input name="name" type="text" id="name" size="30" /></td>
</tr>
..
..
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="20%"><input type="text" name="captcha_code" size="20" maxlength="6" />
<a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">
[ Different Image ]</a></td>
<td width="80%"><img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" /></td>
</tr>
</table>
processForm.php
<?php
session_start();
require("include/application_top.php");
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
//echo "The security code entered was incorrect.<br /><br />";
echo "The code you entered was incorrect. Please go <a href='javascript:history.go(-1)'>back</a> and try again. ";
exit;
}
<!--The rest of the code are just connection to DB-->
Can anyone assist me on this please? Thanks in advance.