导读:织梦教程织梦教程织梦自定义表单用的最多的就是制作留言板,报名等功能,但是添加的字段不填写就能提交,容易被恶意提交,为了防止这些,我们可以把这些字段选项设定为必填项。dede织梦模板织梦模板安装。

织梦自定义表单用的最多的就是制作留言板,报名等功能,但是添加的字段不填写就能提交,容易被恶意提交,为了防止这些,我们可以把这些字段选项设定为必填项。
方法如下:
1. 用php验证
在plus/diy.php的第 40行下加
//增加必填字段判断
if($required!=''){
if(preg_match('/,/', $织梦cms模板required))
{
$requireds = explode(',',$required);
foreach($requireds as $field){
if($$field==''){
&nbs织梦模板安装p; showMsg('带*号的为必填内容,请正确填写', '-1');
exit();
}
}
}else{
if($required==''){
showMsg('带*号的为必填内容,请正确填写', '-1');
exit();
}
}
}
//end |
2.在模版的表单里加<input type="hidden" name="required" value="name,sex" />
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 styldede免费校板下战e="width:97%;" cellpadding="0" cellspacing="1">
<tr>
<td align="right" valign="top">姓名:</td>
<td><input type='text' name='name' id='name' style='width:250px' class='intxt' value='' />
</td>
</tr>
<tr>
<td align="right" valign="top">性别:</td>
<td><select name='sex' style='width:50px'><option value='男'>男</option>
<option value='女'>女</option>
</select>
</td>
</tr>
<tr>
<td align="right" valign="top">电话:</td>
<td><input type='text' name='tell' id='tell' 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='con' id='con' 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' />
<input type="reset" name="reset" value="重 置" class='coolbg' />
</div>
</form>
关键词标签: 织梦 自定义 字段
声明: 本文由我的SEOUC技术文章主页发布于:2023-07-20 ,文章修改织梦dedecms自定义表单字段为必填项的方法主要讲述自定义,字段,织梦网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: http://www.tngdez.cn/article/web_32227.html
为你推荐与修改织梦dedecms自定义表单字段为必填项的方法相关的文章
网站建设技术SEOUC.COM
专注网站建设,SEO优化,小程序设计制作搭建开发定制网站等,数千家网站定制开发案例,网站推广技术服务。
5000+合作客服
8年从业经验
150+覆盖行业
|