I have a site that uses SSI for the headers and footers of the page.
I've created an AJAX request that sent all of the form data to a script on the server that would verify the form and the reCAPTCHA all in one.
I have run into one small problem though. I have been forced to use plain HTML to display the reCAPTCHA due to the fact that all of the file extensions are shtml.
The PHP verification plugin is throwing a fit and telling me "invalid-request-cookie."
I have checked and double checked all of the keys and the only thing that I can come up with is that the request does not like the fact that I am using HTML for displaying the reCAPTCHA and the PHP plugin for verifying it.
I have researched forcing my server to parse the PHP in shtml files so I can display the reCAPTCHA with PHP but due to the fact that the server is a GoDaddy IIS7, that seems to be impossible.
My question is two-fold:
Is what I suspect indeed my problem?
If so, is there any way around this?
Here is my HTML/JavaScript:
<div id="recaptcha-widget">
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=public_key_WAS_inserted_here">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=public_key_WAS_inserted_here"
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
</noscript>
</div>
<p style="padding: 0 45%">
<input type="submit" value="Submit" id="submit-button">
</p>
And here is the JavaScript AJAX request to my PHP validation script.
var dataToSend = $('form #contactForm').serialize();
if($('#contactForm #response').hasClass('error') === false){
jQuery.ajax({
type: 'POST',
url: '../contact.php',
data: dataToSend,
cache: false,
beforeSend: function(){
$('#contactForm #response').show().removeClass().addClass('sending response').html("Sending email. Please wait...");
},
error: function(){
$('#contactForm #response').show().removeClass().addClass('error response').html("Internal error. Please try again.");
},
success: function(response){
if (response !== "The recaptcha response was invalid. Please try again."){
$('#contactForm #response').show().removeClass().addClass('error response').html(response);
} else {
$('#contactForm #response').show().removeClass().addClass('success response').html(response);
}
},
timeout: 20000
});
}
And here is the PHP validation script. I do have the recaptchalib.php on my server.
<?php
require_once('recaptchalib.php');
$privatekey = "privatekey_WAS_inserted_here";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// My verification on this side. This part of the if/else never runs.
}
?>
SOLVED: So I figured out my own problem. In my JavaScript, I was not sending the actual values for the challenge and response fields for the recaptcha. So I fixed that and the reCAPTCHA works flawlessly.