how to perform some action before submit form via .ajaxForm()?

Uday A. Navapara picture Uday A. Navapara · Sep 22, 2014 · Viewed 20.9k times · Source

i am using ajaxForm() frame work to send my data without reloading my page.

    $('#ReplayForm').ajaxForm({ 

      success : function(data){
             alert("Success");
       }   
    });  

now, i want to check some condition before submitting the form and if the condition is false then stop submission else continue.

is there any solution to do this work or is there any way buy which i can perform this operation. Thanks in advance.

Answer

Ashish Vaghasiya picture Ashish Vaghasiya · Sep 22, 2014

Yes, definatly you can handle this situation. you have to call beforesubmit method for this let see one example

$('#ReplayForm').ajaxForm({ 
         beforeSubmit : function(arr, $form, options){
             if("condition is true")
             {
                return true; //it will continue your submission.
             }
             else
             {
                               return false; //ti will stop your submission.
             }

          },
          success : function(data){
              endLoading();
              if(data.result=="success")            
              {
                  showSuccessNotification(data.notification);
              } 
              else
              {
                  showErrorNotification(data.notification);
              }
           }
   });