如何给织梦CMS后台自定义表单添加搜索功能?
实现方法:
1、打开/dede/templets/diy_list.htm 找到
在它的下面加入
<div class="bodytitletxt" 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>
2、打开 /dede/diy_list.php 找到
$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->SetParameter('diyid', $diyid);
在它的下面加入
$datalist->SetParameter('keyword', $keyword);
$datalist->SetParameter('field', $field);
完成。