Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda