Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There was an error running execute() on the reCAPTCHA script

Tags:

amp-html

Form submission failed: Error: There was an error running execute() on the reCAPTCHA script.Error img

When I try to send an amp form with an amp-recaptcha, I get this error. I generated different keys, all have "Allow this key to work with AMP pages" enabled.

Do you have an idea what is the problem? Thx.

<form id="amp-recaptcha-input-form" method="POST" action-xhr="https://example.com/api/push" target="_top">
<fieldset>
  <label>
    <span>Search for</span>
    <input type="search" name="term" required>
  </label>
  <input name="submit-button" type="submit" value="Search">
  <amp-recaptcha-input layout="nodisplay" name="recaptcha_token" 
                       data-sitekey="6LcovLIUAAAAAEfNnsbk69bEKH6LvBM2_2rAxmoj" data-action="recaptcha_example">
  </amp-recaptcha-input>
</fieldset>

<div class="loading-message">
  Loading...
</div>

<div submit-success>
  <template type="amp-mustache">
    <h1>You searched for: {{term}}</h1>
    <div><b>Score:</b> {{score}}</div>
    <div><b>Recaptcha token:</b> {{recaptcha_token}}</div>
    <div><b>Action:</b> {{action}}</div>
  </template>
</div>

<div submit-error>
  <template type="amp-mustache">
    <h1>Error! Please check the JS Console in your dev tools.</h1>
    <p>{{message}}</p>
  </template>
</div></form>
like image 787
Sergey Gong Avatar asked Jan 25 '23 23:01

Sergey Gong


2 Answers

I too am implementing reCAPTCHA on my AMP pages. Firstly you need to use the AMP reCAPTCHA input component in the form (amp-recaptcha-input). After this you will need to verify the token generated for reCAPTCHA v3 the same way as for reCAPTCHA v2. That is, in the code behind using API request (post method) to https://www.google.com/recaptcha/api/siteverify - by sending the secret key, token and user IP address (optional). You'll get a JSON response that you can parse and verify before actually submitting the form data to your database or email code.

Refer:

  1. https://amp.dev/documentation/examples/components/amp-recaptcha-input/
  2. https://developers.google.com/recaptcha/docs/verify
  3. https://developers.google.com/recaptcha/docs/v3
  4. Code sample that came in useful for me - AMP Form to work with PhP
like image 158
Anita Walker Avatar answered Jan 28 '23 13:01

Anita Walker


I had the same problem. There was no error with the code. Google reCAPCHA consol permissions caused the problem.

Go to the Google reCAPCHA Admin site (https://www.google.com/recaptcha/admin/) Settings tab! Set the Domains, add Your site width www And check the „Allow this key to work with AMP pages” box

Like this:

enter image description here

like image 36
vacsati Avatar answered Jan 28 '23 12:01

vacsati