DanBi
DanBi

Reputation: 29

Invisible recaptcha is visible

I have an invisible recaptcha and it's work but it's totally visible to all the users. And I mean this:

enter image description here

And my console says:

Uncaught Error: Missing required parameters: sitekey
at new jl (VM19165 recaptcha__ru.js:575)
at new $Y (VM19165 recaptcha__ru.js:584)
at mt (VM19165 recaptcha__ru.js:599)
at VM19165 recaptcha__ru.js:590
at Array.forEach (<anonymous>)
at hE (VM19165 recaptcha__ru.js:590)
at rI (VM19165 recaptcha__ru.js:593)
at ib (VM19165 recaptcha__ru.js:585)
at VM19165 recaptcha__ru.js:600
at VM19165 recaptcha__ru.js:620

My js code is:

function onSubmit(token) {
alert('thanks ' + document.getElementById('fields[Email]').value);
}

function validate(event) {
event.preventDefault();
grecaptcha.execute();
}

function onload() {
var element = document.getElementById('submit');
element.onclick = validate;
}


<script src="https://www.google.com/recaptcha/api.js" async defer></script>

And html is:

    <input type="text" id="fields[Email]" value="" name="fields[Email]" class="add_field" placeholder="Email" />
<div id='recaptcha' class="g-recaptcha" data-sitekey="6LcaXXXXXXXXXXXXXXXcTqa9o5k"  data-callback="onSubmit" data-size="invisible">
  </div>
</div>
</div>
<div class="col-bs">   
  <button type='submit' id='submit' class="sub-rassilka" >SUBMIT</button>
  </div>

What's the problem, what did I missed?

UPD: I changed the api line to this one, but have the same error in console and recapcha is still shows itself

<script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_6LcaXXXXXXXXXXXXXXXcTqa9o5k" async defer></script>

Upvotes: 1

Views: 1703

Answers (1)

R3tep
R3tep

Reputation: 12864

When you get the api with this line :

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

You don't passe your site key like :

<script src="https://www.google.com/recaptcha/api.js?render=site_key" async defer></script>

Reference : reCAPTCHA v3

You can get your site key here


When you do this :

grecaptcha.execute()

you need to pass the site key too, like :

  grecaptcha.execute('site_key', {action: 'homepage'}).then(function(token) {
     ...
  });

source

Upvotes: 2

Related Questions