I use required
for a 1st check before submitting a form.
<form action="myform.php">
Foo: <input type="text" name="someField" required="required">
<input type="submit" value="submit">
<input type="submit" value="ignore">
</form>
Problem is, that I have an "ignore" button, which submits the form as well and the backend logic then sets a correct state in a DB. In this case (ignore) the validation is not desired (because there is no need to fill in field "Foo").
What's the best way to handle the 2 scenarios?
- I am aware that I could give up "required" and do the validation somewhere else (backend / JavaScript). I am looking for a way to keep the "required".
- I could use some Js
onclick
for the ignore button scenario and remove the attribute just before sending the form ( https://mcmap.net/q/222609/-removing-html5-required-attribute-with-jquery ).
But actually I am looking for something smarter ....
--- Edit ---
Yes, duplicate of Required attribute HTML5
$('form').clone().find(':required').prop('required', false).closest('form').submit();
and the originalform
will stay untouched. Never tried one line coded, it's just to give you the idea. – Lozoya