Views 2 Search Exposed Filter
On a recent site I developed in Drupal 6, was faced with the challenge of implementing filtered search (search results filtered down by taxonomy terms). This can be accomplised use the default advanced search in drupal. but implementing this method would require significant rework of the search interface, not to mention additional templates required to make search results fit in with the rest of the site content which was primarily delivered via CCK/Views.
After some experimenting with a number of alternatives, I ended up implementing a solution that utilized an exposed search filter, and a custom search form to pass keys to the view. Unfortunately, Views 2 requires an exposed filter, so i ended up faking it by enabling the exposed filter, and then hiding it with CSS.
Because the View needs a get request to trigger the filter, simply adding ?keys=search-term to the url won't work. So I rewrote the Local Tasks or menu tabs using localized_options and query settings, then rebuilding the links with the l() function
function hook_menu_item_link($link) {
/*** some code ***/ $link['localized_options']['query'] = 'keys='. $_GET['keys'];
$newLink = l($link['title'], $link['href'], $link['localized_options']); return $newLink;
}
The custom search form looks like this
function module_search_form(){ $form['keys'] = array( '#type' => 'textfield', '#size'=> 15, ); $form['#action'] = base_path() .'search-view/results/all'; $form['submit'] = array( '#type' => 'submit', '#value' => t('Search'), ); $form['#method']= 'get'; return $form; }
And the end result looks like this:
- admin's blog
- Login to post comments