Warm tip: This article is reproduced from stackoverflow.com, please click
forms html validation required

HTML5 required attribute and two submits

发布于 2020-03-28 23:17:08

I have a form with a required input field and two submit buttons:

<form method="POST">
    <input type="text" name="text1" value="<?php echo $temp1 ?>"  required>
    <button type="submit" name="submit">Submit</button>
    <button type="submit" name="auto">Auto</button>
</form>

What i need is to ignore the "required" when a user clicks the "Auto" button and make it work only for the "Submit".

Questioner
John
Viewed
43
Foxseiz 2020-01-31 18:00

Add formnovalidate in your button.

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

<form method="POST">
    <input type="text" name="text1" value="<?php echo $temp1 ?>"  required>
    <button type="submit" name="submit">Submit</button>
    <button type="submit" name="auto" formnovalidate>Auto</button>
</form>

For reference: W3Schools