Google recaptcha v3 recaptcha_response 为空 [英] Google recaptcha v3 recaptcha_response is null
问题描述
我在我的网站上使用 google recaptcha v3,
这是我在我的 html 网页头部添加的代码:
<script src=https://www.google.com/recaptcha/api.js?render=我的公钥"></script>
我在表单中添加了这个:
但是当我提交表单并尝试使用 var_dump() 查看 $_POST['recaptcha_response'] 的内容时它只是一个空字符串:string(0) ""
错在哪里?感谢您的回答!
我尝试了很多更改,但每次都遇到令牌 = 空 "然后我试试这个.. 100% 工作..
在你的 HTML 中
<头>头部><身体><form id="联系人"><div class="col-12"><div class="form-group"><input type="hidden" name="captcha_token" id="recaptchaResponse" data-sitekey="YOUR-SITE-KEY">
<div class="col-12"><button type="submit" class="btn btn-lg" id="submit-btn">提交按钮>
</表单><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script><script src="https://www.google.com/recaptcha/api.js?onload=ReCaptchaCallbackV3&render=YOUR-SITE-KEY"></script></html>
然后加入你的js文件
$(document).ready(function(){设置间隔(函数(){ReCaptchaCallbackV3();}, 90000);$(document).on("submit",'#contact',function (e) {var token = $('[name="g-recaptcha-response"]').val();控制台日志(令牌);});});var ReCaptchaCallbackV3 = function() {grecaptcha.ready(函数(){grecaptcha.execute('YOUR-SITE-KEY', { action: 'contact' }).then(function (token) {});});}
i am using google recaptcha v3 in my website ,
here is the code i have added in my html web page in the head:
<script src="https://www.google.com/recaptcha/api.js?render=my public key"></script>
<script>
grecaptcha.ready(function () {
grecaptcha.execute('my public key', { action: 'contact' }).then(function (token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
ecaptchaResponse.value = token;
});
});
</script>
and i added this in my form :
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
but when i submit the form and try to see the content of $_POST['recaptcha_response'] with var_dump() it is just an empty string : string(0) ""
where is the mistake ? thanks for answers !
i tried lots of changes but everytime i get " token = null " then i try this.. 100% working....
in Your Html
<html>
<head>
</head>
<body>
<form id="contact">
<div class="col-12">
<div class="form-group">
<input type="hidden" name="captcha_token" id="recaptchaResponse" data-sitekey="YOUR-SITE-KEY">
</div>
</div>
<div class="col-12">
<button type="submit" class="btn btn-lg" id="submit-btn">
SUBMIT
</button>
</div>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js?onload=ReCaptchaCallbackV3&render=YOUR-SITE-KEY"></script>
</body>
</html>
after then add in your js file
$(document).ready(function(){
setInterval(function(){
ReCaptchaCallbackV3();
}, 90000);
$(document).on("submit",'#contact',function (e) {
var token = $('[name="g-recaptcha-response"]').val();
console.log(token);
});
});
var ReCaptchaCallbackV3 = function() {
grecaptcha.ready(function () {
grecaptcha.execute('YOUR-SITE-KEY', { action: 'contact' }).then(function (token) {});
});
}
这篇关于Google recaptcha v3 recaptcha_response 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!