Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

271
Vistas
How can I submit a form using JavaScript while still running HTML validations (minlength, maxlength, pattern...)

I'm using ReCAPTCHA which means that I have to submit the form from JS, not HTML, but HTMLFormElement.submit() doesn't confirm the form is valid first and I have written some checks that I would like to still be effective. The only solutions I see are for writing all the checks in JS (for people wanting custom checks) and ones that use JQuery. None of the solutions seem to have the browser-styled error messages that show below the field which isn't preferable. Is there a simple way to do this or do I have to do something like iterating over all the fields and validate them manually? Preferably, I would also like to run the checks before ReCAPTCHA even generates a score, but I doubt this is possible because of how limited ReCAPTCHA's API seems to be. It's worth noting that I manually validate the values server-side already, as I'm aware it would be easy for people to get round these checks, but I'd like to avoid unnecessary POST requests and be able to use the browser-styled error messages.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First of all, you have too many questions/issues in one post. You're normally expected to try and figure things out on your own as much as you can before asking. Here are some issues I picked up:

  1. Form validation process does not conflict with form submission process.
  2. Whether recaptcha goes before or after the validation is not an important issue, but vast majority of forms where it's used, do it after the validation.
  3. Try to avoid using JQuery since it adds an unneeded dependency. Pure JS is just as powerful.
  4. If you want a nicely styled error message - that's a completely different issue that has no relation to recaptcha or form submission. You now talking about DOM editing and styling.
  5. Running something before recaptcha is a question of timing things rather than limitations of Recaptcha's API. It's completely in your power.
  6. Server-side validation and client-side validation are both needed, but they largely play different roles: client is more for user-friendly error reporting while server is a real validation of user input. It's a good practice to keep them in tight sync. So having BE validation doesn't excuse you from having FE validation.
  7. You don't need additional POST requests for FE validation. Additional communication with the back-end during validation is needed for things that the client can't validate.
  8. Finally, you can do your validation before submitting the payload to the server. I suggest looking at the concept of async: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function This is to make your form submission after the response from Recaptcha comes and after you're done with your FE validation. Promises is how it's usually comfortable to work with: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda