5

When I use this code, I only manage to retrieve recaptcha_response_field. If I remove recaptcha_response_field, I retrieve recaptcha_challenge_field. However, I am unable to retrieve the two at the same time. I only managed to send 1 data.

challengeField = $("#recaptcha_challenge_field").val();
responseField = $("#recaptcha_response_field").val();

var html = $.ajax(
    {
        global: false,
        type: "POST",
        async: false,
        dataType: "html",
        data: "recaptcha_response_field=" + responseField + "&recaptcha_challenge_field=" + challengeField,
        url: "../ajax.recaptcha.php"
    }).responseText;

if(html == "success")
{
    $("#captchaStatus").html("Success. Submitting form.");
    return true;
}
else
{
    $("#captchaStatus").html("Your captcha is incorrect. Please try again");
    Recaptcha.reload();
    return false;
}

4 Answers 4

2

you wrote this line data: "recaptcha_response_field=" + responseField + "&recaptcha_challenge_field=" + challengeField, was wrong.

you can try this:

$.ajax({
   type: "POST",
   url: "some.php",
   data: { name: "John", location: "Boston" }
 }).done(function( msg ) {
          alert( "Data Saved: " + msg );
     });

or data: {recaptcha_response_field : responseField , recaptcha_challenge_field :challengeField

thanks, Chintu

Sign up to request clarification or add additional context in comments.

Comments

1

Try

data: {
    recaptcha_response_field: responseField,
    recaptcha_challenge_field: challengeField
}

??

What do you mean that $_POST["recaptcha_response_field"] and $_POST["recaptcha_challenge_field"] are not both set "inside" ajax.recaptcha.php.

That's impossible Firebug's Net-Tab shows that the request just works fine.

Did you check your server logs (enable post data logging temporarily )

2 Comments

Yeah that's exactly what I mean. I don't know why however... I'm using joomla if that can helps. There's nothing relevant in the servers logs. Thank you
just btw. can't you just use some of the existing recaptcha / joomla plugins? extensions.joomla.org/extensions/search/reCaptcha or just google for it
1

Maby something like this?

var challengeField  = $("#recaptcha_challenge_field").val(); 
var responseField   = $("#recaptcha_response_field").val();

/* Debug */ alert ("Going to send channengeField with value '" + challengeField + "', and responseField with '" + resonseField + "'");

$.post ("../ajax.recaptcha.php", { 
        recaptcha_response_field:   responseField, 
        recaptcha_challenge_field:  challengeField 
    },
    function(data) 
    {
        /* Debug */ alert ("Data Recieved: " + data);

        if (data == "success")
        {
            $("#captchaStatus").html("Success. Submitting form.");

            return true; 
        }
        else
        {
            $("#captchaStatus").html("Your captcha is incorrect. Please try again"); 
            Recaptcha.reload(); 

            return false; 
        }
    });

Comments

0

You can try like this

  data: "recaptcha_response_field=" + $("#recaptcha_challenge_field").val() + "&recaptcha_challenge_field=" + ("#recaptcha_response_field").val(),

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.