Hi all,
I tried to do a CAPTCHA "error message - I would like an error message (pop up) show on the first page (checkForm.php) when user entered a wrong code/secureimage. At the moment the error message showing on the next page (processFrom.php) which isn't really what I want.
Can anyone show me what is the correct way to achieve what I need please?
Here I show you the snippets of the code:
checkForm.php
<?php
session_start();
require("include/application_top.php");
?>
<head>
<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=tel]').parent().removeClass('error');
if($('[name=tel]').val()==""){
error_num++;
error_mesg += "Please enter telephone no\n";
$('[name=tel]').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');
}
..
..
..
});
});
</script>
</head>
<body>
<form name="check_form" id="check_form" method="post" action="processForm.php">
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="20%">Name</td>
<td width="80%"><input name="name" type="text" id="name" size="30" /></td>
</tr>
<tr>
<td>Tel</td>
<td><input name="tel" type="text" id="tel" size="30" /></td>
</tr>
</table>
<dl>
Please enter the text that you see in the image into the box on below.
</dl>
<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="#">
[ Different Image ]</a></td>
<td width="80%"><img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image"/></td>
</tr>
</table>
<div class="btn"><input name="btn_submit" type="button" id="btn_submit" value="Submit" /></div>
</div>
</form>
</body>
</html>
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;
}
..
..
<!--SNIPPETS DATABASE CONNECTION-->
$table_fields = array("name", "tel");
..
..
$connection = mysql_connect (DB_SERVER, DB_USER, DB_PASS) or
die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db (DB_NAME, $connection);
mysql_query ($query, $connection)
or die(mysql_error()."\n<br />This is the query:\n<br />".$query);
..
..
header ("Location:thankyou.php");
}
?>