SearchboxRecognition

Summary: Determine which of a page's multiple searchboxes was used
Version: 1.0
Status: works for me
Maintainer: RandyB
Categories: Searching, PHP55
Users: +1 (view / edit)

Questions answered by this recipe

  • How do I put multiple searchboxes on a single page, each producing its own results, without confusing the user?
  • How do I retain the normal behavior of the page header's searchbox when I put a special searchbox on a page?

All sections are optional, you can remove those that do not apply to your recipe, and add new ones.

Description

This recipe lets you put multiple searchboxes on a single page and know before displaying the results (or even deciding whether to display the results) which search box was used for the query. This makes it easier to avoid surprising or confusing the user when multiple search boxes coexist on a page.

Installation

First, install the recipes Cookbook:HttpVariables and Cookbook:Request. This allows your markup to easily recognize query parameters, one of which will be submitted automatically as a flag by each search box. This recipe uses the "req" parameter, since that seems unlikely to be entered by a user in the query string under normal circumstances.

(The Cookbook:Request recipe can be omitted if you are willing to write more difficult to read markup.)

Configuration

Usage

Here is markup demonstrating the technique:

To search the entire wiki, use the normal search box in the header. 
To search just pages in a particular page group, use the appropriate box below.

(:comment --- searchbox 1 ---:)
(:searchbox count=3 group={$Group} label="Search this group" req=1:)

(:comment --- searchbox 2 ---:)
(:searchbox count=3 group=PmWiki label="Search the PmWiki group" req=2:)

(:comment --- display results if and when they occur ---:)
(:if1 request q:)(:comment --- a query was entered into a search box ---:)
(:if request req 1:)
!! First 3 results from the first search box (group={$Group})
(:elseif request req 2:)
!! First 3 results from the second search box (group=PmWiki)
(:else:)
!! All results from the entire wiki
(:ifend:)
(:searchresults:)
(:if1end:)

Notes

Change log / Release notes

Initial release November 14, 2013

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See also

Contributors

Comments

See discussion at SearchboxRecognition-Talk?

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.