找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1392|回复: 0

[分享] dede自定义表单必填项的方法

[复制链接]
发表于 2018-3-5 08:15:31 | 显示全部楼层 |阅读模式 来自 河南省新乡市
织梦自定义表单必填项的方法,一般是js来进行验证判断,今天就分享下在php里验证必填项。
用php验证:
1. 在plus/diy.php 的第40行下加
  1. //增加必填字段判断
  2. if($required!=''){
  3. if(preg_match('/,/', $required))
  4. {
  5. $requireds= explode(',',$required);
  6. foreach($requiredsas $field){
  7. if($field==''){
  8. showMsg('带*号的为必填内容,请正确填写','-1');
  9. exit();
  10. }
  11. }
  12. }else{
  13. if($required==''){
  14. showMsg('带*号的为必填内容,请正确填写','-1');
  15. exit();
  16. }
  17. }
  18. }
  19. //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='**2'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="<a href="http://www.genban.org/" title="织梦模板"><u>dede</u></a>_fields"value="name2,text;**2,select;tell2,text;add,text;con2,text"/>
<input type="hidden" name="<a href="http://www.genban.org/" title="织梦模板"><u>dede</u></a>_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>

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-5-2 07:28 , Processed in 0.049689 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表