Bypass HTML "required" attribute when submitting [duplicate] Bypass HTML "required" attribute when submitting [duplicate] javascript javascript

Bypass HTML "required" attribute when submitting [duplicate]


No JavaScript, no second form needed, and the validation can stay:

For exactly this use case the HTML5 spec has designed the formnovalidate attribute for submit elements (like <input type=submit>), as one of the attributes for form submission:

The formnovalidate attribute can be used to make submit buttons that do not trigger the constraint validation.

So simply put

<form action="myform.php">  Foo: <input type="text" name="someField" required>  <input type="submit" value="submit">  <input type="submit" value="ignore" formnovalidate></form>


Your #2 is a common approach. Something like:

$('input[value="ignore"]').click(function() {    $(this).siblings('input[type="text"]').removeAttr('required');});

Might have to use mousedown to beat submit.


If you don't want to use Javascript, you could make them separate forms and have all the inputs set to hidden for the ignore form.

Not the best option, but it is an alternative.