Im正在尝试通过延迟执行直到提交它来避免recaptcha v3超时。遗憾的是,当我按下submit按钮时,它什么也不做。这是我的代码。
JAVASCRIPT
<script>
grecaptcha.ready(function() {
document.getElementById('contactForm').addEventListener("submit", function(event) {
event.preventDefault();
grecaptcha.execute('xxxxxx', {
action: 'homepage'
}).then(function(token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
document.getElementById('contactForm').submit();
});
}, false);
});
</script>HTML
<form method="POST" action="<? echo $url . '/nueva/'; ?>" id="contactForm">
<div class="form-group row">
<label class="col-3 col-form-label" for="palabra">address</label>
<div class="col-9">
<input id="address" name="address" type="text" class="form-control here">
</div>
</div>
<div class="form-group row">
<div class="offset-3 col-9">
<button name="submit" type="submit" class="btn btn-primary btn-block">Enviar</button>
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
</div>
</div>
</form>发布于 2020-11-04 12:03:25
我猜是php + JQuery,我的代码是ASP.NET MVC + javascript,但是你可以试试。
Javascript
grecaptcha.ready(function() {
document.getElementById('enviar').addEventListener("click", function(event) {
return new Promise((res, rej) => {
grecaptcha.ready(function () {
grecaptcha.execute('xxxxxx', { action: 'homepage' }).then(function (token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
});
});
});
}, false);
});HTML
<button id="enviar" name="submit" type="submit" class="btn btn-primary btn-block">Enviar</button>https://stackoverflow.com/questions/61396732
复制相似问题