我有表格在我的网站中添加新的管理员,如下所示: -
<form class="form-horizontal" action="adminmodule.php?action=add" enctype="multipart/form-data" id="addadmin">
<div class="control-group">
<label for="inputWarning" class="control-label">UserName</label>
<div class="controls">
<input type="text" id="admins_user" name="admins_user" class="span6 m-wrap" >
<span class="help-inline"></span>
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Full Name</label>
<div class="controls">
<input type="text" id="admins_fullname" name="admins_fullname" class="span6 m-wrap" >
</div>
</div>
<div class="control-group">
<label for="inputSuccess" class="control-label">Pass</label>
<div class="controls">
<input type="text" id="admins_pass" name="admins_pass" class="span6 m-wrap">
</div>
</div>
<div class="control-group">
<label for="inputSuccess" class="control-label">Email</label>
<div class="controls">
<input type="text" id="admins_email" name="admins_email" class="span6 m-wrap" >
</div>
</div>
<div class="control-group">
<label for="inputSuccess" class="control-label">Type</label>
<div class="controls">
<select id="admins_type" name="admins_type" class="span6 m-wrap">
<option value="0">admin</option>
<option value="1">manager</option>
<option value="2">submanager</option>
</select>
</div>
</div>
<div class="control-group">
<label for="inputSuccess" class="control-label">status</label>
<div class="controls">
<select id="admins_status" name="admins_status" class="span6 m-wrap">
<option value="0">active</option>
<option value="1">un active</option>
</select>
</div>
</div>
<div class="form-actions">
<button class="btn green" type="button" value="saveadd" id="saveadd" onClick="add_admin();">save</button>
<button class="btn" type="button" value="canceladd">cancel</button>
</div>
</form>
并且我不会在div中显示错误的按摩,我会让它接近这样: -
<span class="help-inline"></span>
所以,我的问题是我无法通过我的div中的jquery验证显示来自函数的错误消息。
我的功能是
$("#saveadd").click(function(){
function submitForm(){
var validator = $("#addadmin").validate({
rules: { name: "required", email: "required",
},
errorElement: "span" ,
messages: { name: " Enter name",
email: " enter email",
} });
if(validator.form()){ // validation perform
$('form#addadmin').attr({action: 'mycontroller'}); $('form#addadmin').submit();
}
}
});