The V3 challenge is often wrong, because you have to submit your form in less than 2 minutes (before the challenge expire).
That's because the challenge is asked too soon.
reCAPTCHA tokens expire after two minutes. If you're protecting an action with reCAPTCHA, make sure to call execute when the user takes the action rather than on page load.
So I changed the JavaScript a bit to call execute on form submit, not on page load.
Also added this:
grecaptchaInput.value = ''; // Always reset the value to get a brand new challenge
Because the FormType is keeping the old challenge when the form is submitted with error, and ReCaptcha is not populating a fresh token if there is already one in the field.
The V3 challenge is often wrong, because you have to submit your form in less than 2 minutes (before the challenge expire). That's because the challenge is asked too soon.
As per the documentation:
https://developers.google.com/recaptcha/docs/v3
So I changed the JavaScript a bit to call execute on form submit, not on page load.
Also added this:
Because the FormType is keeping the old challenge when the form is submitted with error, and ReCaptcha is not populating a fresh token if there is already one in the field.