我有一个带2个按钮的表单。一个按钮以ajax格式提交表单,另一个按钮以正常方式提交表单。
$('#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'
}
}
}
}
});
这是表单部分内的按钮的HTML部分
<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>
表单未提交。我做错了什么?
答案 0 :(得分:24)
答案 1 :(得分:0)