织梦自定义表单默认是没有搜索功能的,,当留言版块提交的内容很多的时候后台就没办法快速查找你想要的留言记录,接下来教大家如何实现留言表单搜索功能。
第一步:打开 /dede/templets/diy_list.htm
找到<div style="padding-left:10px;"><?php echo $diy->name;?>内容列表</div>
下面加入:
<div style="padding-left:10px;"> <form name='form1' action="diy_list.php"> <input type='hidden' name='action' value='list' /> <input type='hidden' name='diyid' value='<?php echo $diy->diyid; ?>' /> 关键字: <input type='text' name='keyword' size='20' value="<?php echo $keyword; ?>" /> <select name="field"> <?php foreach($fieldlist as $k=>$fielddata) { if($k==$field) { echo "<option value='{$k}' selected>{$fielddata[0]}</option>/r/n"; } else { echo "<option value='{$k}'>{$fielddata[0]}</option>/r/n"; } } ?> </select> <input type='submit' name='sb' value='确定' class="coolbg np" /> </form> </div> |
第二步:打开 /dede/diy_list.php
找到 $query = "SELECT * FROM {$diy->table} ORDER BY id DESC"; 到$datalist->SetParameter('diyid', $diyid);
替换成:
$query = "SELECT * FROM {$diy->table} ORDER BY id DESC"; if(empty($keyword)) { $keyword = ''; $addquery = ''; } else { $addquery = " WHERE {$field} LIKE '%".trim($keyword)."%' "; } $query = "SELECT * FROM {$diy->table} $addquery ORDER BY id DESC"; $datalist = new DataListCP(); $datalist->pageSize = 10; $datalist->SetParameter('action', 'list'); $datalist->SetParameter('diyid', $diyid); $datalist->SetParameter('keyword', $keyword); $datalist->SetParameter('field', $field); |
*注:主要是添加红色字体代码字段。
第三步:浏览器更新缓存刷新后台查看吧。
演示图: