开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜