How to create a custom search box
How to create a custom search box
Categories:This is an example on how you can create a custom search box for your drupal site. The code below renders a text box and a button. When you perform a search, drupal will only look for the keyword inside the node types specified below (page, recipe, product, blog_article).
You can just copy and paste this code into a block.
<form action="/search/node" method="post" id="search-form" class="search-form">
<div class="form-item">
<input type="text" class="input-text" value="" size="25" name="keys" />
<input type="submit" value="Search" name="op" title="Search" alt="Search" />
<input type="hidden" value="<?php print drupal_get_token('search_form'); ?>" name="form_token" />
<input type="hidden" value="search_form" id="edit-search-form" name="form_id" />
<input type="hidden" name="type[blog_article]" id="edit-type-blog_article" value="blog_article" />
<input type="hidden" name="type[page]" id="edit-type-page" value="page" />
<input type="hidden" name="type[recipe]" id="edit-type-recipe" value="recipe" />
<input type="hidden" name="type[product]" id="edit-type-product" value="product" />
</div>
</form>IMPORTANT NOTE! Since this approach hard-codes Advanced Search options in to hidden fields in the search form, to use the above approach, all users needing to search *must* have access to Advanced Search options. Sounds obvious, but thought I'd mention it.
Obviously, if it is not desired to expose Advanced Search options to some roles, you can always use hook_form_alter to unset the options in the search form for those roles.
Taken from: http://drupal.org/node/141788
- 379 reads
Post new comment