Google Invisible ReCaptchaにフォームを送信してもらうようにしてみましょう。 私の問題は、ReCaptchaが目に見えないことではなく、 "古い" recaptchaがポップアップしているようです。なぜか分からない。私のサイトキーは目に見えないrecaptchaです。私を助けてください。Google Invisible ReCaptcha invisible
私はAPIをロードしていますまず第一に:
<script src='https://www.google.com/recaptcha/api.js?render=explicit&onload=onScriptLoad' async defer></script>
私のフォームは次のようになります。
<form method="post" id="contact-form-face" class="clearfix" onsubmit="return false">
<input type="text" required name="name" value="name" onFocus="if (this.value == 'name') this.value = '';" onBlur="if (this.value == '') this.value = 'name';" />
<button type="submit" id="sendButton" data-size="invisible" class="g-recaptcha contact_btn" onclick="onSubmitBtnClick()" value="send" >send</button>
</form>
JS:
window.onScriptLoad = function() {
// this callback will be called by recapcha/api.js once its loaded. If we used
// render=explicit as param in script src, then we can explicitly render reCaptcha at this point
// element to "render" invisible captcha in
var htmlEl = document.querySelector('.g-recaptcha');
// option to captcha
var captchaOptions = {
sitekey: 'XXXXXXX',
size: 'invisible',
// tell reCaptcha which callback to notify when user is successfully verified.
// if this value is string, then it must be name of function accessible via window['nameOfFunc'],
// and passing string is equivalent to specifying data-callback='nameOfFunc', but it can be
// reference to an actual function
callback: window.onUserVerified
};
// Only for "invisible" type. if true, will read value from html-element's data-* attribute if its not passed via captchaOptions
var inheritFromDataAttr = true;
console.log("render now!");
// now render
recaptchaId = window.grecaptcha.render(htmlEl, captchaOptions, inheritFromDataAttr);
};
// this is assigned from "data-callback" or render()'s "options.callback"
window.onUserVerified = function (token) {
alert('User Is verified');
console.log('token=', token);
};
// click handler for form's submit button
function onSubmitBtnClick() {
var token = window.grecaptcha.getResponse(recaptchaId);
// if no token, mean user is not validated yet
if (!token) {
// trigger validation
window.grecaptcha.execute(recaptchaId);
return;
}
var xhrData = {
'g-recaptcha-response': token
// more ajax body/data here
};
};
、物事をより明確にするには:このreCAPTCHAのうまく動作し、コールバックが読み込まれ、検証はうまく動作します....唯一の問題は、このrecaptchaがinvisibでなければならないことですそれはありませんがILE、:/
これはAPIが私が人間であるかどうかを検出できないためですか? – Jones
私は同じ問題があります。私は当初は明示的にレンダリングしていましたが、それはフォームの検証を不正にしました。今、私は明示的に実行しようとしていますが、ドキュメンテーションはそれが示唆していますが、互換性がないようです。 – DAB