Manu
Manu

Reputation: 21

How to stop form execution without using prevent default?

My form is a payment gateway integration form. I need to save details to the database first, then only need to send the details to the payment gateway. When I submit the form I need to check it's validity with some php operation. After doing the php operation I need to actually submit the form.

Can you suggest a good method to solve this?

This is my form

<form method="post" action="paymentgatway url " id="myForm">

<input type="text" name="name1" requried>
<input type="text" name="cash" requried>
<input type="submit" name="submit1" id="submit1" value="submit">
</form>

and PHP

var $myForm = $('#myForm');
    if ($myForm[0].checkValidity()) {
     <?php some php code ?>

     then submit the form 

    }   
    else{

          $myForm.find(':submit').click();

    } 

Upvotes: 0

Views: 535

Answers (2)

fdorantesm
fdorantesm

Reputation: 3388

There's no way using natural submit events. You may using a button with a click event that trigger a submit.

Upvotes: 0

Mitali
Mitali

Reputation: 166

You can change input type submit to input type button.It won't submit your form. On click of that button you can have your php check using ajax. after success response, you can submit the form using script $('#myForm').submit();

Upvotes: 2

Related Questions