Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
Integrating HTMX with Google reCaptcha

I have a basic HTMX form, that I want to integrate with Google reCaptcha (v3) so that when the user clicks the submit button, some JavaScript will call the reCaptcha API to obtain a token, which is then added to a hidden field which the back end can pick-up.

Here is my form:

<form id="form" hx-post="/page" hx-target="#content">
    <input id="recaptcha-token" type="hidden" name="ReCaptchaToken" />
    <button type="submit">Submit</button>
</form>

Initially I was thinking of hooking into the htmx:configRequest event to modify the parameters sent in the request like so:

<script>
    document.body.addEventListener('htmx:configRequest', (e) => {
        grecaptcha.ready(function() {
          grecaptcha.execute('reCAPTCHA_site_key', {action: 'submit'}).then(function(token) {
            e.detail.parameters.ReCaptchaToken = token;
          });
        });
    });   
 </script>

But of course this doesn't work because of async nature of execute - i.e. the event handler finishes before resolving the execute promise.

How can I integrate the reCaptcha call before the HTMX form post?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!