Fork me on GitHub
programer.tips, another cool thing from @nghuuphuoc!

Examples / Advance

Using Ajax to submit the form

By triggering the success.form.bv event, we can use Ajax to submit the form data.

$(document).ready(function() {
    $(form)
        .bootstrapValidator({
            ... options ...
        })
        .on('success.form.bv', function(e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);
            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');
            // Use Ajax to submit form data
            $.post($form.attr('action'), $form.serialize(), function(result) {
                // ... Process the result ...
            }, 'json');
        });
});

In the example above, you can see the form is prevented from doing default submission by using

e.preventDefault();

Comments

Don't submit the issue here

If you want to report a bug, please submit the issue on Github. For a general question or feedback, use the form below.