Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
Results 1 to 2 of 2
-
09-20-2015, 02:15 PM #1New Coder
- Join Date
- Oct 2014
- Posts
- 15
- Thanks
- 1
- Thanked 0 Times in 0 Posts
NoCaptcha reCaptcha with ajax always fails
May I have some guidance on this issue please, totally lost so far. I am attempting to process my form via ajax on the backend using jQuery and it keeps failing. I tested the form and am receiving the post data, but each time it just fails. (I had tested this with normal processing and it worked, also I got it working clientside using "grecaptcha.getResponse()"--though am wondering how that works without the secret key?)
My AJAX:
And PHP:Code:var request=$.ajax({ url:'./includes/contact.php', type:'post', dataType:'html', data:$('#contact-form').serialize(), ...
PHP Code:require_once('../includes/recaptcha.php');
$secret="...";
$response=null;
$reCaptcha=new ReCaptcha($secret);
$response=$reCaptcha->verifyResponse($_SERVER['REMOTE_ADDR'],$_POST['g-recaptcha-response']);
if($response!=null&&$response->success){
echo "Thank you for submitting the form.";
} else {
echo "...FAIL...";
}
exit();
-
09-20-2015, 07:37 PM #2New Coder
- Join Date
- Oct 2014
- Posts
- 15
- Thanks
- 1
- Thanked 0 Times in 0 Posts
Alright, so it seems that using serialize fails every time. However, so far after several tests this method seems to be working instead:
AJAX side for data:
data:{captchaResponse:$("#g-recaptcha-response").val()},
And on PHP side replacing the $_POST with:
$var=filter_input(INPUT_POST,'captchaResponse');



Reply With Quote
