0

I'm using the jquery validation plugin. My goal is to check whether a user is present in the database before sending the form. If present then I ask it to connect by displaying a modal connection

function checkemail() {
    jQuery.noConflict();
    $("#frompopupcontactpublic").validate({
                  rules: {
                    email: {
                      required: true,
                      email: true,
                      remote: "/?controller=pjAdminUsers&action=pjActionCheckEmail"
                    }
                  }


            });
    }
    function opencnx() {
           $("#cnxfrom").modal('show'); 

    }

    $(document).on('click', '#idbtn', function () {
        jQuery.noConflict();
        $.ajax({
            type        : "POST",
            cache   : false,
            url     : "/send_contact.php",
            data        : $(this).serializeArray(),
            beforeSend: function () {
                if(!checkemail()) {
                    //opencnx();
                    alert('here');
                    return false;
                } else {
                    alert('or here');

                }

            },
            success: function(msg){
            if(msg=='send')
                {
                        $(".reponsecontenu").html(msg);
                        $(".reponse").modal('show');

                }
            },
            error: function () {
                  alert("failure");
                $("#result").html('There is error while submit');
            }
        });
        return false;
    }); 

Do you know why the validation () starts before beforeSend ?

pablofr
  • 134
  • 1
  • 14

1 Answers1

0

I've looked at your HTML on jsFiddle, and this code:

beforeSubmit: function () {
        return $("#contact").valid();
    }

will never return true, as the id of your form is actually frompopupcontact and not contact.:

<form class="col-md-10 col-md-offset-1 col-xs-12 col-xs-offset-0" id="frompopupcontact" >

So try changing your js to this:

 beforeSubmit: function () {
        return $("#frompopupcontact").valid();
    }
ED-209
  • 4,706
  • 2
  • 21
  • 26
  • @pablofr Your jsfiddle doesn't do anything at all. And it still has #contact as the form id. – ED-209 Nov 20 '15 at 15:37
  • on line 23 ? tis return $("#contact").valid(); ? – pablofr Nov 20 '15 at 16:01
  • @pablofr Yes, and it should be return $("#frompopupcontact").valid(); – ED-209 Nov 20 '15 at 16:14
  • i try it on jsfiddel on line 1 $("#contact").validate({ and on line 23 return $("#contact").valid();, the same id, dont work :( – pablofr Nov 20 '15 at 21:35
  • @pablofr I think you're not understanding me. The ID of your form in your HTML is not 'contact', so $("#contact") will not work. You need to use $("#frompopupcontact") – ED-209 Nov 21 '15 at 11:07