濮阳杆衣贸易有限公司

主頁(yè) > 網(wǎng)站建設(shè) > 建站知識(shí) > 織夢(mèng)自定義表單字段為必填項(xiàng)的教程

織夢(mèng)自定義表單字段為必填項(xiàng)的教程

POST TIME:2020-04-11 14:00

織夢(mèng)自定義表單用的最多的就是制作留言板,報(bào)名等功能,但是添加的字段不填寫就能提交,容易被惡意提交,為了防止這些,我們可以把這些字段選項(xiàng)設(shè)定為必填項(xiàng)。

方法如下:
 
1. 用php驗(yàn)證
 
在plus/diy.php的第 40行下加
 
//增加必填字段判斷
if($required!=''){
if(preg_match('/,/', $required))
{
$requireds = explode(',',$required);
foreach($requireds as $field){
if($$field==''){
showMsg('帶*號(hào)的為必填內(nèi)容,請(qǐng)正確填寫', '-1');
exit();
}
}
}else{
if($required==''){
showMsg('帶*號(hào)的為必填內(nèi)容,請(qǐng)正確填寫', '-1');
exit();
}
}
}
//end
 
2.在模版的表單里加<input type="hidden" name="required" value="name,sex" />
 
value 就是必須字段,多個(gè)用“,”隔開。
 
參考案例分享:www.genban.org 網(wǎng)站建設(shè)
 
<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='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">備注內(nèi)容:</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' />
&nbsp;
<input type="reset" name="reset" value="重 置" class='coolbg' />
</div>
</form>
 


收縮
  • 微信客服
  • 微信二維碼
  • 電話咨詢

  • 400-1100-266
青田县| 扎兰屯市| 格尔木市| 江北区| 龙川县| 株洲市| 宣化县| 策勒县| 宜春市| 论坛| 嘉鱼县| 孟津县| 通榆县| 蒙山县| 马公市| 榆树市| 林西县| 郸城县| 新化县| 漳州市| 酒泉市| 额尔古纳市| 莱州市| 平度市| 高雄县| 龙陵县| 汉川市| 宁化县| 广安市| 山东省| 长子县| 天津市| 榆中县| 精河县| 北海市| 阳朔县| 新化县| 双辽市| 陆川县| 临安市| 滨海县|