Search code examples
htmlformsvalidationrequired

HTML5 required attribute and two submits


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".


Solution

  • 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