Firstly, I know there are better solutions than than google recaptcha but I really am stuck with this for now. Using the ReCaptchaV3 v.3.2.2 from Sepia River. We know that this times out if the form isn’t completed within two minutes so I implemented something I found online that refreshes the token before the two minutes is up. The problem with it though, is that if you complete the form quite quickly google recaptcha also throws an error. The following is the relevant chunk that ships with the extra…
<script src="https://www.google.com/recaptcha/api.js?render=[[+site_key]]&hl=[[++cultureKey]]"></script>
<input type="hidden" name="[[+token_key]]">
<input type="hidden" name="[[+action_key]]" value="[[+form_id]]">
<script>
grecaptcha.ready(function() {
grecaptcha.execute('[[+site_key]]', {action: '[[+form_id]]'}).then(function(token) {
document.querySelector('[name="[[+token_key]]"]').value = token;
});
});
</script>
The modified chunk I’ve been using is as follows and works when the time taken is over two minutes. As I understand it, it refreshes the token so that the time out doesn’t happen…
<script src="https://www.google.com/recaptcha/api.js?render=[[+site_key]]&hl=[[++cultureKey]]"></script>
<input type="hidden" name="[[+token_key]]">
<input type="hidden" name="[[+action_key]]" value="[[+form_id]]">
<script>
setInterval(function () {
grecaptcha.ready(function() {
grecaptcha.execute('[[+site_key]]', {action: '[[+form_id]]'}).then(function(token) {
document.querySelector('[name="[[+token_key]]"]').value = token;
});
});
}, 90 * 1000);
</script>
That does work but not if you’re too quick. My understanding is that the token shouldn’t be requested until the form is submitted but I can’t find a complete enough example for a minion like me to understand. Any help would be greatly appreciated.