View Full Version : Captcha and Form validation

08-22-2009, 04:55 PM
Hello Guys,

I have a contact form which is set up with captcha for security, so no spammers, which note works fine, but when i use form validation, it just doesnt work i narrowed it down to that when i insert this link it just doesnt work. Well if put this line then validation works if i dont then captcha works fine.

<form method="post" action="" onsubmit="return formValidator()">

this is my php script, but please note that for online purpose i have missed certain stuff, but the stuff i will provide will be enough for you to help me out.

$publickey = "12";
$privatekey = "123";
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
# are we submitting the page?
if ($_POST["submit"]) {
$resp = recaptcha_check_answer ($privatekey,
if ($resp->is_valid) {
$sql = "INSERT INTO $db_table(status) values ('".mysql_real_escape_string(stripslashes($_REQUEST['ItemNumber']))."')";
if($result = mysql_query($sql ,$db)) {
echo '<script type="text/javascript">';
echo 'window.location = "http://www.1.co.uk/thankyou.html"';
echo '</script>';
} else {
echo "ERROR: ".mysql_error();
} else {
# set the error code so that we can display it. You could also use
# die ("reCAPTCHA failed"), but using the error message is
# more user friendly
$error = $resp->error;
echo recaptcha_get_html($publickey, $error);

Thank you guys for your help and time.