1

I'm trying to use reCaptcha in a dynamic form of mine. At the simplest level, I want the form to not go through if the reCaptcha is invalid. Here's the part of the code that will post the form:

if($("#registerPost").valid() && /*reCaptcha valid*/)
{
    $.post('php/registerPost.php', $('#registerPost').serialize(), function(data){
        window.location.replace("mainpage");
    }
}

I also would need to show a div if the reCaptcha is put through and returned invalid, but I know how to do that.

So my question is - how can I display a reCaptcha and have it check itself, all dynamically without a page refresh, like the rest of my form, and then if it is valid, to have a boolean be true, and if invalid, to have a boolean be false?

0

1 Answer 1

1

I would make an ajax call to verify the correctness of re-captcha and based on the return value, I would decide on, if I need to post the form.

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

2 Comments

+1 but that's not quite enough: the ajax call needs to also return a token that then gets submitted back to you with the form. Otherwise you can't trust the form post hasn't been maliciously generated either, pretending that the captcha was approved. You could also do this by e.g. tracking that the same client IP (or session if you had one) has recently made a successful captcha check before accepting the post.
How exactly would I do that? Would I make a separate PHP file with the reCaptcha code in it, or would I do it all in JS?

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.