您现在的位置是:首页 > 教程 > dedecms教程dedecms教程
织梦自定义表单字段为必填项的方法
傲蕾2024-07-31 17:20:45dedecms教程已有人查阅
导读织梦自定义表单用的最多的就是制作留言板,报名等功能,但是添加的字段不填写就能提交,容易被恶意提交,为了防止这些,我们可以把这些字段选项设定为必填项。
织梦自定义表单用的最多的就是制作留言板,报名等功能,但是添加的字段不填写就能提交,容易被恶意提交,为了防止这些,我们可以把这些字段选项设定为必填项。
方法如下:
1. 用php验证
在plus/diy.php的第 40行下加
方法如下:
1. 用php验证
在plus/diy.php的第 40行下加
//增加必填字段判断
if($required!=''){
if(preg_match('/,/', $required))
{
$requireds = explode(',',$required);
foreach($requireds as $field){
if($$field==''){
showMsg('带*号的为必填内容,请正确填写', '-1');
exit();
}
}
}else{
if($required==''){
showMsg('带*号的为必填内容,请正确填写', '-1');
exit();
}
}
}
//end
2.在模版的表单里加
<input type="hidden" name="required" value="name, " />
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='name' id='name' style='width:250px' class='intxt' value='' />
</td>
</tr>
<tr>
<td align="right" valign="top">性别:</td>
<td><select name=' ' 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; 2,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>
本文标签:
很赞哦! ()
相关文章
随机图文
-
dedecms取消栏目列表页文章标题设置推荐后加粗的方法
如果使用的是织梦的默认模板,列表页的文章标题不管你是否设置加粗,或是是否选择了推荐,都进行了加粗。 但如果你用的是非官方默认模板,又不想列表也的 -
怎么批量删除织梦cms遗留无用的图片代码
网站运营时间长了总会留下一些过时的没用的内容,特别是采集的数据,其中难免有些不需要或者过时的内容,但在删除文章时Dedecms并不能帮我们删除其中的附带的图片 -
dedecms织梦副栏目名称和链接调用的方法
打开 \include\extend.func.php 在最下面加入/*** 获取副栏目链接和名称** @access public* @para -
dedecms织梦模板中当前栏目的上级栏目名称怎么调用
此dedecms教程的目的是让大家使用{dede:type typeid=’1′}[field:typename/]{/dede:type} 标签时能够获得当前栏目的上一级栏目信息。
留言与评论 (共有 条评论) |