Skip to content
Advertisement

HTML Form onSubmit being bypassed

I’m new to HTML and JS and I’m trying to setup a “Contact” page using GitHub Pages. I am using formspree.io to submit the forms and e-mail to the app mail account.

Here is the deal: I’m trying to setup a simple validation just to verify if the form fields aren’t empty (there is no need for a server-side validation), but the “onSubmit” response seems to be bypassed every single time.

Here is my contact.html file:

JavaScript

If I open the file locally on Google Chrome, it works just fine, the alerts show up and the form is not submitted until all fields have been filled. When I open it on my GHPages, however, it bypasses the validate function and proceeds to Formspree captcha page.

A little bit more context (not sure if it influences)…

This file is being included on my index.html file using a JS function. My index consists of 2 tabs that load a different HTML when clicked. Here is the GitHub repo for more information: TellMeApp/support.

What I have already tried:

  • Correcting the Javascript function: I am aware that if an error is raised on the function, the submission follows on without validation.
  • Creating an additional function to submit the form via JS: works the same locally, not online…
  • Looking for solutions on Github Pages help: did not found anything related to this subject.

Any thoughts on what could be wrong here?

I thank you in advance!

Advertisement

Answer

Instead of using the onsubmit attribute, you can use the required attribute for the inputs like so:

JavaScript

If you are interested in reading more about the required attribute, you can find it here: HTML required Attribute – W3Schools.com

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