专注前端,专注网页设计分享 - (网页制作/模板制作/设计)755150799 织梦模板 | 网页特效 | 网站模板 | 建站教程 | Tag标签 | 联系站长

dede自定义表单必填项的方法

时间:2014-05-10 15:16:58来源:学技巧网站制作 作者:学技巧网页制作 阅读:0次 【 点评一下

织梦自定义表单必填项的方法,一般是js来进行验证判断,今天就分享下在php里验证必填项。

用php验证:

1. 在plus/diy.php 的第40行下加
//增加必填字段判断
if($required!=''){
if(preg_match('/,/', $required))
{
$requireds= explode(',',$required);
foreach($requiredsas $field){
if($$field==''){
showMsg('带*号的为必填内容,请正确填写','-1');
exit();
}
}
}else{
if($required==''){
showMsg('带*号的为必填内容,请正确填写','-1');
exit();
}
}
}
//end


2.在模版的表单里加 <inputtype="hidden" name="required" value="name,qq"/>
value 就是必须字段 多个用, 隔开。

案例分享:

<form action="/plus/diy.php"enctype="multipart/form-data" method="post">
<input type="hidden"name="required" value="name,qq" />
<input type="hidden" name="action" value="post"/>
<input type="hidden" name="diyid" value="1"/>
<input type="hidden" name="do" value="2"/>
<table style="width:97%;" cellpadding="0"cellspacing="1">
<tr>
 <td align="right"valign="top">姓名:</td>
<td><input type='text'name='name2' id='name2' style='width:250px' class='intxt' value='' />
</td>
</tr>
<tr>
 <td align="right"valign="top">性别:</td>
<td><selectname='sex2'style='width:50px'><optionvalue='男'>男</option>
<optionvalue='女'>女</option>
</select>
</td>
</tr>
<tr>
 <td align="right"valign="top">电话:</td>
<td><input type='text'name='tell2' id='tell2' style='width:250px' class='intxt' value='' />
</td>
</tr>
<tr>
 <td align="right"valign="top">地址:</td>
<td><input type='text'name='add' id='add' style='width:250px' class='intxt' value='' />
</td>
</tr>
<tr>
 <td align="right"valign="top">备注内容:</td>
<td><input type='text'name='con2' id='con2' style='width:250px;height:100px'  class='intxt' value=''/>
</td>
</tr>
<input type="hidden" name="dede_fields"value="name2,text;sex2,select;tell2,text;add,text;con2,text"/>
<input type="hidden" name="dede_fieldshash"value="78764e448024ba3607705cbf961ebf3f"/></table>
<div align='center'style='height:30px;padding-top:10px;padding-left:130px'>
<input type="submit" name="submit" value="提 交"class='coolbg' />
&nbsp;
<input type="reset" name="reset" value="重 置"class='coolbg' />
</div>
</form>

  • 用微信  “扫一扫”

    将文章分享到朋友圈。

    关注公众号:xue-jiqiao

本文版权归原作者所有,转载请注明原文来源出处,学技巧网站制作感谢您的支持!