JQuery + jQuery Form Submit Plugin + jQuery Validation Plugin

I understand that this has been asked several times, but I wonder if you can help me in the situation.

Reference Information. I tried to create a form that submits using Ajax (jQuery Form Submit). Which I received in order to work fine, and then I wanted to receive confirmation in the form. Which I was able to get to work with the jQuery form validation plugin. But I can’t get them to work together.

Basically, it simply represents a form of weather or is not "valid."

I hope this is something simple. Can you see the problem?

$('#addCompany').submit(function() { 
    $('#addCompany').ajaxSubmit({
        target:        '.response',   
            beforeSubmit:  validateForm,   
        success:       function () {
            $('.response').fadeIn('slow');
        }
     }); 

    });  //END SUBMIT FUNCTION
  }); //END DOCUMENT

  function validateForm() {
        $("#addCompany").validate({
            rules: {
                company: "required",
                contactEmail: "required"
                },
             messages: {
                company: "Please enter the clients company",
                                contactEmail: "Please enter a valid email address",
                   }
        });
    }
+3
source share
2 answers

. . . :

$("#addCompany").validate({
  rules: {
    company: "required",
    contactEmail: "required"
  },
  messages: {
    company: "Please enter the clients company",
    contactEmail: "Please enter a valid email address",
  },
  submitHandler: function(form) {
    $(form).ajaxSubmit({
      target: '.response',   
      success: function() {
        $('.response').fadeIn('slow');
      }
    });
  }
});
+2

- validateForm. true, .

-

return $("#addCompany").....
0

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


All Articles