<?php include $this->admin_tpl('meta', 'admin');?>
<title>添加自定义表单 - YzmCMS内容管理系统</title>
</head>
<body>
<article class="page-container">
<div class="formdoby_normal"> 
	<form method="post" onsubmit="return dosub(this)">
		<ul>
			 <li class="yzm-explain-box"><label><span class="c-red">*</span>表单名称</label>
			 	<input type="text" class="input" name="name" value="" placeholder="如：用户信息表单">
			 	<span class="yzm-explain">给表单起一个名称，<br>例如：用户信息表单</span>
			 </li>
			 <li class="yzm-explain-box"><label><span class="c-red">*</span>表名</label>
			 	<input type="text" class="input" name="tablename" value="" placeholder="如：info">
			 	<span class="yzm-explain">表名只能由英文字母、数字<br>和下划线组成，例如：info</span>
			 </li>
			 <li><label>启用</label>
			 <span class="span_input">
			 	<label class="label_radio"><input name="disabled" type="radio" value="0" checked> 是</label>
			 	<label class="label_radio"><input name="disabled" type="radio" value="1"> 否</label>
			 </span>
			 </li>
			 <li><label>开启验证码</label>
			 <span class="span_input">
				<label class="label_radio"><input name="check_code" type="radio" value="1" checked> 是</label>
				<label class="label_radio"><input name="check_code" type="radio" value="0"> 否</label>
			 </span>
			</li>
			 <li><label>开启邮件提醒</label>
			 <span class="span_input yzm-explain-box">
			 	<label class="label_radio"><input name="sendmail" type="radio" value="0" checked> 否</label>
			 	<label class="label_radio"><input name="sendmail" type="radio" value="1"> 是</label>
				<span class="yzm-explain">请先正确配置邮箱</span>
			 </span>
			 </li>
			 <li><label>允许游客提交表单</label>
			 <span class="span_input">
			 	<label class="label_radio"><input name="allowvisitor" type="radio" value="0" checked> 否</label>
			 	<label class="label_radio"><input name="allowvisitor" type="radio" value="1"> 是</label>
			 </span>
			 </li>
			 <li><label>表单简介</label>
			 	<span class="span_input"><textarea name="description" class="textarea" style="width:400px"></textarea></span>
			 </li>
			 <li><label>显示页模板</label>
			 <span class="span_input">
				<select id="show_template" name="show_template">
					<option value="">请选择</option>
				  <?php 
				   foreach($show_temp as $key => $val){
					   $str = $data['show_template']==$key ? 'selected' : '';
					   echo '<option '.$str.' value='.$key.'>'.$val.'('.$key.')</option>';
				   }
				  ?>			
				</select>
			 </span>
			 </li>				 
			 <li>
			 	<input type="hidden" name="dosubmit" value="1">
			 	<input class="dosubmit w_100 btn-primary radius" type="submit" value="提交">
			 	<input class="btn w_100 btn-default radius h35" type="button" value="取消" onclick="yzmcms_close()">
			</li>
		</ul>
	</form>
</div>
</article>
<?php include $this->admin_tpl('footer', 'admin');?>
<script type="text/javascript">
	function dosub(obj){
		 var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){0,29}$/;	
		 if(obj.name.value==''){
			 layer.msg('表单名称不能为空！', {icon:2});
			 return false;
		 }
		 if(obj.tablename.value.length<1 || obj.tablename.value.length>30){
		 	layer.msg('表名长度必须为1-30位！', {icon:2});
		 	return false;
		 }
		 if(!reg.test(obj.tablename.value)){
			layer.msg('表名必须为英文、数字或下划线！', {icon:2});
			return false;
		 }
		 
		if($("select[name='list_template']").val()==''){
			layer.msg('请选择列表页模板！', {icon:2});
			return false;
		}
		if($("select[name='show_template']").val()==''){
			layer.msg('请选择显示页模板！', {icon:2});
			return false;
		}		 
		 
        $.ajax({
            type: 'POST',
            url: '<?php echo U('add');?>', 
            data: $(obj).serialize(),
		    dataType: "json", 
            success: function (msg) {
				if(msg.status == 1){
					layer.msg(msg.message, {icon:1,time:1500}, function(){
						parent.location.reload();     
					});
			    }else{
					layer.msg(msg.message, {icon:2});
				}
            }
        })		 
		return false;			 
	}
</script> 

</body>
</html>