【发布时间】:2023-03-09 19:56:02
【问题描述】:
我对 Google Recaptcha V3 有疑问。 Id 确实适用于单个表单,但如果页面中的表单超过 1 个,则仅适用于第一个表单。
如何使其适用于所有形式?
我知道问题出在id="recaptchaResponse",但我不知道如何解决这个问题!那里有一些类似的问题,但找不到解决方案。
Javascript:
<script src="https://www.google.com/recaptcha/api.js?render=key1"></script>
<script>
grecaptcha.ready(function () {
grecaptcha.execute('key2', { action: 'contact' }).then(function (token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
});
});
</script>
表格:
<form class="user" action="" method="post" name="form1" id="form1">
<input type="hidden" name="source" value="form1">
<button type="submit" class="btn btn-success">Submit 1</button>
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
</form>
<form class="user" action="" method="post" name="form2" id="form2">
<input type="hidden" name="source" value="form2">
<button type="submit" class="btn btn-success">Submit 2</button>
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
</form>
请帮忙!提前致谢!
【问题讨论】: