Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you submit HTML5 form WITHOUT validating?

So I have this form and I really want to use html5 validation. Problem is, there are two things my form needs to do:

  • Simply save the current state so it can be reloaded later (via jsp/servlets) (WITHOUT VALIDATING)

  • Actually submit the form (validate it before submitting)

Is there a way to turn off validation for a given button/submit but keep it for the other?

My workaround would be to use an AJAX call for the former and regular submit for the latter, but it kind of messes up the system I have in place.

like image 524
CoqPwner Avatar asked Jun 15 '26 02:06

CoqPwner


1 Answers

You can add the "novalidate" attribute when the user clicks on a given button.

<form method="post" action="/foo" novalidate>...</form>

This disables html validation. Add it again when you want your final submission.

EDIT

Apparently there's a better option, the formnovalidate attribute, that you can add to a specific field (which apparently is exactly what you want):

<form action="demo_form.asp">
  E-mail: <input type="email" name="userid"><br>
  <input type="submit" value="Submit"><br>
  <input type="submit" formnovalidate="formnovalidate" value="Submit without validation">
</form>
like image 154
Julien Avatar answered Jun 17 '26 16:06

Julien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!