I’m using reCAPTCHA and I’d like to show the response if the CATPCHA was filled in incorrectly as an alert(); rather than it loading a new page. How can I do that?
This is the form action:
<form id="form" method="POST" action="verify.php">
With this in the verify.php file:
<?php
require_once('recaptchalib.php');
$privatekey = "(my key)";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>
Call your method on form submit like–
OR use jquery, something like that —