该系统表单提交全部以`ajax`方式进行提交,我们只需在模板文件内引入公共`comm.js`文件,然后通过该方式提交既可实现`ajax`提交,范例如下:
~~~
<form action="<?php echo url('dianxiaoer/basic_setting/edit');?>" method="post" class="ajax">
<div class="ncap-form-default">
<input type="hidden" name="id" value="<?php echo $info->id;?>">
<dl class="row">
<dt class="tit">
<label for="retain_domain"><em>*</em>门店角色</label>
</dt>
<dd class="opt">
<input class="ui-input w200" type="text" placeholder="" name="name" value="<?php echo $info->name;?>">
</dd>
</dl>
<dl class="row">
<dt class="tit">
<label for="retain_domain"><em>*</em>唯一标识</label>
</dt>
<dd class="opt">
<input class="ui-input w200" type="text" placeholder="" name="slug" value="<?php echo $info->slug;?>"<?php if($_GET['id']){echo 'readonly';}?> >
</dd>
<dt class="tit">
</dt>
</dl>
<p class="tc martb36"><button type="submit" id='submitForm' class="btn-submit submit">保存</button></p>
</div>
</form>
~~~
我们在`comm.js`中自动加载`ajax_form`方法,通过该方法实现表单提交等功能:
~~~
function ajax_form(ele){
$(ele).ajaxForm({
dataType: 'json',
success: function(data) {
if(data.status == 1){
if( data.url){
$('#new').hide();
alert_box(data.msg);
setTimeout(function(){
window.location.href = data.url;
},1000);
}
}else{
$("input,select ").css('border',"");
if(data.messages){
var msg = data.messages;
if(jQuery.isArray(msg)){
$.each(msg,function(index,element){
$("*[name='"+index+"'] ").css('border','1px solid red');
});
}else{
alert_box(data.msg);
}
}else{
alert_box(data.msg);
}
}
}
});
}
~~~