A button like input / submit that performs validation and submit via jquery ajax?

I am trying to use jquery validator plugin and submit form via ajax in jquery .....

Validator plugin works with <input type="submit" value="Add a client" id="clientadd"/>, but my submit form works with <input type="button" value="Add a client" id="clientadd"/>.....

<form id="addform" autocomplete="off">
 //My controls here
</form>

I did not specify the attributes here actionand methodsince I will submit my form using jquery.ajax().... Any suggestion on how to make both work together.

+3
source share
2 answers

You can specify submitHandler , which will submit the form after successful validation:

$('form').validate({
    submitHandler: function(form) {
       // TODO: submit your form in ajax here
    }
});

, jQuery.form ajaxify :

$('form').validate({
    submitHandler: function(form) {
        $(form).ajaxSubmit();        
    }
});
+2

action="", HTML, type="submit". submit jQuery :

$('#addform').submit(function() {
  // your stuff here to process the form

  // end with
  return false;
});
+1

Source: https://habr.com/ru/post/1746236/


All Articles