[pmwiki-users] Using Searchbox: restricting to a ptv
Petko Yotov
5ko at 5ko.fr
Wed Jan 27 22:42:38 CST 2010
On Monday 25 January 2010 15:04:38, Graham Archer wrote :
> I would like to setup a searchbox where if the user types in the word
> Apple, it would only apply to the ptv Fruit and not to any other ptv.
> At the moment in the above example the search returns both pages 1 and 2
> results, whereas I would want it only to return page 1 with the ptv
> (:Fruit:Apple:)
Unfortunately, this is only possible out of the box if the user writes in the
search field :
$:Fruit=Apple
It is quite complex to do it from a dedicated search box, and you should know
some PHP and about PmWiki Forms.
In config.php, you can intercept the PTV search string and append it to the
regular search string which is "q", something like:
foreach ($_REQUEST as $key=>$value) {
if (substr($key, 0, 4)=='ptv_' && $value>'') {
$_REQUEST['q'] .= " $:".substr($key, 4)."=\"$value\"" ;
}
}
In the search form, instead of or in addition to the input field named "q",
you need to have a field named ptv_Fruit.
So, in a default HTML form in the skin template, you replace
<input type='text' name='q' /> with
<input type='text' name='ptv_Fruit' />
Or, if you have a search form in a wiki page,
(:input form action={*$PageUrl} method=get:)
(:input hidden n {*$FullName}:) (:comment this line may be optional:)
(:input hidden action search:)
(:input text $:Fruit:) (:input submit value="Search":)
(:input end:)
(:searchresults:)
Here, instead of (:input text q:) we have (:input text $:Fruit:).
Petko
More information about the pmwiki-users
mailing list