Skip to content
Advertisement

How to wait until the user finished the tasks after grecaptcha.execute()? reCAPTCHA v2 invisible

I would like to make my own website, where I use reCAPTCHA. However, I don’t know how to wait after grecaptcha.execute() until the user has completed the tasks. Because now the link is called directly without passing the tasks. For the rest I use the standard Google Script https://developers.google.com/recaptcha/docs/invisible It is the reCAPTCHA v2 invisible.

I would be happy about answers.

JavaScript

Advertisement

Answer

The following code does this:

  1. The <button class="g-recaptcha"... is the Automatically bind the challenge to a button. It will automatically trigger the invisible recaptcha when the button is clicked.
  2. Once the recaptcha is completed it will add a hidden field named g-recaptcha-response which contains the token and then run the onSubmit callback which submits the form.
JavaScript

Important: You still need to verify the token g-recaptcha-response server side. See Verifying the user’s response. Without verifying the token, adding the recaptcha to the frontend doesn’t stop anyone from submitting the form.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement