11

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?

bjb568
  • 11,089
  • 11
  • 50
  • 71
Hacker Rocker
  • 251
  • 2
  • 4
  • 13

2 Answers2

26

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.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Phuoc Nguyen
  • 541
  • 4
  • 4
0

It could be a handful of things:

  • form id matches both html and js
  • submitHandler is actually working?
  • is the library even loaded?

That's just at the top of my head. A fiddle might help.

gmslzr
  • 1,211
  • 1
  • 10
  • 15