我的知识记录

PbootCMS定义搜索字段示例



<form action="{pboot:scaction}"  method="get">
关键字:<input type="text" name="keyword" >
<input type="hidden" name="field" value="title" >
<button type="submit">搜索</button>
</form>

或:

<form action="{pboot:scaction}"  method="get">
<select name="field">
<option value="title">内容标题</option>
<option value="content">内容详情</option>
</select>
关键字:<input type="text" name="keyword" >
<button type="submit">搜索</button>
</form>

通过添加隐藏域传递field值来控制搜索的字段,也可以同时设置多个字段,如: value="title|content" ,当然这只是方式之一,后面还有!
### 3、定义更多搜索条件示例

<form action="{pboot:scaction}"  method="get">
关键字:<input type="text" name="keyword" >
<input type="hidden" name="field" value="title" >
<input type="hidden" name="scode" value="2,3" >
<button type="submit">搜索</button>
</form>

这里只定义搜索的字段和搜索的分类。可传递的字段须在 content_query_fields() 白名单内或为 ext_* 扩展字段,非法字段会被忽略。如 author 为 admin:name="author" value="admin";也可使用非隐藏域做综合搜索。
如果需要定义的scode分类有多个,可以用逗号隔开;scode 会按栏目树展开子栏目后再搜索,不是等值匹配。同时需要注意,如果表单传递的分类和字段无效时,要考虑结果页循环是否做了限制。
(V1.3.7+)如果有多个搜索表单想定义不同的结果页模板,那么可以传递searchtpl字段来定义模板页,如:

<input type="hidden" name="searchtpl" value="test.html" >

searchtpl 必须匹配 ^[w]+.html$(仅字母数字下划线 + .html),否则回退为 search.html。
### 4、多条件综合搜索示例

<form action="{pboot:scaction}"  method="get">
内容:<input type="text" name="content" >
标题:<input type="text" name="title" >
作者:<input type="text" name="author" >
<input type="hidden" name="scode" value="2,3" >
<button type="submit">搜索</button>
</form>

这里自定义了三个字段,同样仅限白名单字段与 ext_*。
如果URL采用兼容模式,这时候搜索应该使用POST,或者在首行添加隐藏域,<input type="hidden" name="search" >。注意:{pboot:keyword} 只读取 GET 的 keyword,在纯 POST 提交时该标签为空。

PbootCMS定义搜索字段示例

标签:

更新时间:2026-10-09 13:17:12

上一篇:PbootCMS用于在个人中心我的评论页面调用,具体使用建议参考默认模板

下一篇:PbootCMS搜索结果列表