$(document).ready(function(){
$('#signup').bootstrapValidator({
message: 'This value is not valid',
fields: {
fname: {
message: 'The first name name is not valid',
validators: {
notEmpty: {
message: 'The first name is required \n and can\'t be empty'
},
stringLength: {
min:4,
max: 30,
message: 'The first name must be more than 4 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The first name can only consist of alphabetical, number, dot and underscore'
}
}
},
});
});
有人可以说,如果已经验证,我应该把ajax用于在php中提交我的表单。
答案 0 :(得分:1)
试试这个: -
$('#signup').bootstrapValidator({
message: 'This value is not valid',
fields: {
fname: {
message: 'The first name name is not valid',
validators: {
notEmpty: {
message: 'The first name is required \n and can\'t be empty'
},
stringLength: {
min: 4,
max: 30,
message: 'The first name must be more than 4 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The first name can only consist of alphabetical, number, dot and underscore'
}
}
},
}
})
.on('success.form.bv', function (e) {
//prevent submit form
e.preventDefault();
//put your ajax call here
/* Send the data using post and put the results in a div */
$.ajax({
url: "ajax.php",
type: "post",
data: val,
datatype: 'json',
success: function(data){
},
error:function(){
}
});
});
答案 1 :(得分:0)
使用这样的代码:
$('#signup').bootstrapValidator({
...
})
.on('success.form.bv', function(e) {
//Perform form submition (the way you preffer, for example:)
$.post($('#signup').attr('action'), $('#signup').serialize(), function(response){
//Form submition response
});
})
.on('error.form.bv', function(e) {
//Process error
});;