Check that reCAPTCHA has been marked

Asked

Viewed 1,652 times

3

I am using an email form in PHP with POST method and use Google Recaptcha. I need to check in Javascript or jQuery, if reCAPTCHA was marked only then enable the send button.

The current code:

var checado = false;

jQuery("#recaptcha-anchor").each(function(){
 if($(this).prop("checked")=="checked")
   checado=true;
});

if(checado=true){
 return true;
 jQuery('#submitBtn').prop('disabled', false);

}else{
 return false;    
}

NOTE: I don’t have access to PHP code if it needs to be changed.

1 answer

5


Stackoverflow Response Translation in English:

Google has a call back option for when the checkbox is checked.

Google has a return for when the checkbox is checked.

In the div who makes the call from reCAPTCHA add this:

data-callback="nome_da_funcao"

It’ll stay that way:

<div class="g-recaptcha" data-callback="recaptchaCallback" data-sitekey="sua_key"></div>

Then you create your function:

 function recaptchaCallback()
 {
    jQuery('#submitBtn').prop('disabled', false);
 }

When the reCAPTCHA is checked, and the box marked, callback is triggered and its function is executed.

You can access the original response in English.

Remembering that its original code has code after the return, when you use the return you make an output of its function, and the code after the return is inaccessible, so it must come before the return.

  • With this return I can already ignore the whole process of checking by PHP described in this reply?

  • No, because the user can simply remove the script client-side. The verification shall be made server-side also.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.