I have two domains, a and b, both with reCAPTCHA enabled. I'm using the same codebase for both websites, but the reCAPTCHA implementation works on a but not on b. Here's the setup:
a: The reCAPTCHA keys were created by a friend 2 years ago. The keys are for reCAPTCHA v3, as the site uses grecaptcha.execute.
b: The reCAPTCHA keys were created today, and I used reCAPTCHA v3 for this domain as well.
On b, I get an error:
contact.php:37 Uncaught (in promise) TypeError: Cannot set properties of null (setting 'value')
at contact.php:37:71
(anonymous) @ contact.php:37
Promise.then
then @ recaptcha__en.js:591
(anonymous) @ contact.php:36
Promise.then
(anonymous) @ recaptcha__en.js:138
(anonymous) @ recaptcha__en.js:195
(anonymous) @ recaptcha__en.js:196
(anonymous) @ recaptcha__en.js:472
(anonymous) @ recaptcha__en.js:196
(anonymous) @ recaptcha__en.js:1132
(anonymous) @ recaptcha__en.js:1142
Here's the client-side code I’m using:
<script src=".js?render=mysitekey"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('mysitekey', {action: 'contact_form'})
.then(function(token) {
document.getElementById('g-recaptcha-response').value = token;
});
});
</script>
Also I noticed that the reCAPTCHA tokens generated for the two domains have different lengths:
For a, the token is about 1100 characters.
For b, the token is around 2400 characters.
Can someone tell me what is wrong with this code?