可见的重新捕获是可见的

时间:2019-02-18 11:32:44

标签: javascript html recaptcha

我有一个不可见的Recaptcha,它可以正常工作,但对所有用户完全可见。我的意思是:

enter image description here

我的控制台说:

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

我的js代码是:

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>

而html是:

    <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>

出什么问题了,我错过了什么?

UPD:我将api行更改为这一行,但在控制台中有相同的错误,并且recapcha仍然显示自身

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

1 个答案:

答案 0 :(得分:2)

使用此行获取api时:

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

您不会像这样传递站点密钥:

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

参考:reCAPTCHA v3

您可以获取站点密钥here


执行此操作时:

grecaptcha.execute()

您还需要传递站点密钥,例如:

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

source