How to call a function if all field are valids on validation JQuery

24 Views Asked by At

I need to call a function after all fields are successfully validated

$('.form').validate({
            rules:{
               nome:{
                minlength: 2
               },
               email:{
                email: true
               },
               telefone:{
                number: true,
                minlength: 10,
                maxlength: 10
               },
               mensagem: { 
                required: true
                }
            }, messages:{
                nome:{
                    required: "Por favor digite seu nome!",
                    minlength: "No mínimo 2 caracteres para o nome"
                },
                email: "Por favor digite seu email!",
                telefone:{
                    required: "Por favor digite seu telefone!",
                    minlength: "Telefone no mínimo 10 caracteres",
                    maxlength: "Telefone no máximo 10 caracteres"
                } ,
                mensagem: "Por favor digite sua mensagem!"
            },
        })

I tried "submitHandler:" and "Success:" But none of them work, I don't know if I'm doing something wrong.

Im expecting to run this function when all fields are correct:

        $(function(){
            $('.form').submit(function(){
                $.ajax({
                url: 'validation.php',
                type: 'POST',
                data: $('.form').serialize(),
                success: function(data){
                    $('.mostrar').html(data);
                }
            })
            return false;
            })
        })
0

There are 0 best solutions below