简体   繁体   中英

PHP one form with two submit buttons and different validation

I have a single form with two submit buttons and there's a javascript validation in this form, is it possible to activate this validation only in one of my submit buttons? I tried to create an input button instead of input submit with an onclick event and then submit through javascript function, but it didn't work.

<form id="myform" action="my_action.php" method="post" enctype="multipart/form-data" onsubmit="return IsValidForm();">
    <!-- ... -->
    <input type="submit" name="auto" />
    <input type="submit" name="manual"/>
</form>

You're on the right track with moving the event handler to the submit button, you just shouldn't stop it being a submit button.

<form id="myform" action="my_action.php"
      method="post" enctype="multipart/form-data">
    <!-- ... -->
    <input type="submit" name="auto" onclick="return IsValidForm();">
    <input type="submit" name="manual">
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM