BootstrapValidator form submit not working

Hacker Rocker picture Hacker Rocker · May 20, 2014 · Viewed 11.3k times · Source

I have a form with 2 buttons. One button submits the form in ajax format and another button submits the form in normal fashion.

$('#form_createAd').bootstrapValidator({
    submitHandler: function(validator, form, submitButton) {
        if (submitButton.attr('value') == "cart"){
            submit_cartDetails(); //This function submits details thru ajax post
        } else {
            form.submit(); // Also Tried $('#form_createAd').submit()
        }
    }, fields: {
        title: {
            message: 'The username is not valid',
            validators: {
                notEmpty: {
                    message: 'The username is required and can\'t be empty'
                },
                stringLength: {
                    min: 6,
                    max: 30,
                    message: 'The username must be more than 6 and less than 30 characters long'
                },
                regexp: {
                    regexp: /^[a-zA-Z0-9_\.]+$/,
                    message: 'The username can only consist of alphabetical, number, dot and underscore'
                }
            }
        }
    }
});

This Is The HTML Part Of Buttons Inside Form Section

<button  id="cart" value="cart" class="btn btn-primary" >Add To Cart</button>             
<button type="submit" name="submit" value="proceed" class="btn btn-success">Proceed</button>

The form doesn't submit. What did I do wrong?

Answer

Phuoc Nguyen picture Phuoc Nguyen · Sep 3, 2014

I'm the creator of BootstrapValidator plugin.

The issue is caused by using submit to name the submit button. Changing name="submit" to something else will fix the issue.