开发者

How to integrate jquery.bvalidator and jquery.form plugins?

开发者 https://www.devze.com 2023-03-11 02:25 出处:网络
I\'m trying to use these plugins to validate (bValidator) and submit my form (Form plugin), without success:

I'm trying to use these plugins to validate (bValidator) and submit my form (Form plugin), without success:

    var myvalidator = $('#contForm').bValidator();
    if(myvalidator.isValid()) {
    $('#contForm').ajaxSubmit(function() { 
            alert("Thank you for your message!"); 
            return false;
    });
    }

The validation part is ok, however the ajaxSubmit is not working...

Thanks in advance for 开发者_开发技巧your help! `


The easiest way to do this is:

$('#contForm').bValidator();

$('#contForm').ajaxForm(function() { 
    alert("Thank you for your message!");
});

.bValidator() must be called before .ajaxForm() to stop form submit if validation fails.

You can also do like this:

var myvalidator = $('#contForm').bValidator();

$('#contForm').submit(function(){
    if(myvalidator.isValid()){
        $(this).ajaxSubmit(function() { 
            alert("Thank you for your message!");
        }); 
    }
    return false;
});


var myvalidator = $('#myForm').bValidator();

$('#myForm').submit(function()
{
    //call ajax here
    ....

    //disable submit post
    return false;
});
0

精彩评论

暂无评论...
验证码 换一张
取 消