I want plugin js : validationform (from formvalidation.io) validate form before button submit send ajax to server. My code as :
1> Button :
<button type="submit" class="btn btn-success " id="button">Add</button>
2> I check validate form with plugin validationform :
$('#formSubmit').bootstrapValidator({ feedbackIcons: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, fields: { PhoneNumber: { message: 'Not Null', validators: { notEmpty: { message: 'Not Null' }, stringLength: { min:9, max: 11, message: '9->11' }, } },};
3> I call Ajax in button submit :
$('#button').click(function(e){ e.preventDefault(); // I want to validate form in here,if invalid=>show message error like plugin,if valid => call Ajax $.ajax({ cache: false, async: true, type: 'POST', dataType: 'json', data: form.serialize(), url: '@Url.Action("MyAction","MyController")', success: function (re) { ...... });