heliosk
heliosk

Reputation: 1159

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>

Upvotes: 0

Views: 470

Answers (1)

Quentin
Quentin

Reputation: 943579

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>

Upvotes: 1

Related Questions