I've added a ReCaptcha to my contact form. Everything works with it; if the form is filled in and the captcha is correct, a "thank you" message is displayed, if the captcha fails, a "sorry, try again" message. Both messages are displayed on the same page, but without the form. However, it's come to my attention that if some users get the captcha wrong, when they refresh the page, they have to re-enter all of their information. There is a php/html file with the form and the captcha, and a php file that has the captcha validation. I've been googleing like crazy and trying different suggestions, but nothing seems to be quite right. I don't have a preference if a failed captcha is treated with an error message on the same page (so the user still sees all of the form fields and can retry the captcha) or if the completed form fields are redisplayed with the users answers when the page is refreshed; I've been searching both ways. I'm not sure if it's browser specific or if I've just changed my settings at some point, but with Chrome and IE, the form fields are empty if the captcha fails and you refresh the page, but Firefox preserves the info.
Here is what I have for the validation:
require_once('recaptchalib.php');
$privatekey = "6LfO0-wSAAAAAJr0VE9asN";
$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 ("There was a problem with your captcha. Please go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
$success = mail($email_address, $subject, $message, $headers);
}
Thank you for any help or suggestions!