Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  • Thread Tools
  • Rate This Thread
  1. #1
    New 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:

    Code:
     var request=$.ajax({
        url:'./includes/contact.php',
        type:'post',
        dataType:'html',
        data:$('#contact-form').serialize(),
        ...
    And PHP:

    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(); 

  2. #2
    New 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');


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •