Pedro Posada | How to create a custom search box

How to create a custom search box

Posted on October 2, 2008 - 3:37pm
<< 33 of 54 >>

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

Submitted by jerabelle (not verified) on March 20, 2011 - 7:17pm.

Thanks for all the enthusiasm of posting good article with good ideas. It’s very useful. Check for more information at www.mgupload.net to enrich your knowledge about hormones

Jerabelle
www.mgupload.net

Submitted by Ibiza (not verified) on July 17, 2011 - 7:38pm.

I have been reading your posts frequently. I need to say that you are doing a fantastic work. Please keep up the great work.
playa real ibiza

Submitted by mts (not verified) on July 22, 2011 - 9:35pm.

You have a very good site, well constructed and very interesting i have bookmarked you hopefully you keep posting new stuff, many thanks.
data transcription services

Submitted by Anonymous (not verified) on September 25, 2011 - 10:32pm.

Excellent read, I just passed this onto a colleague who was doing a little research on that. And he actually bought me lunch because I found it for him smile So let me rephrase that.ICANN | Programming Competition | Domain Registrar Software | Hosting Reseller | Domain Name | Domain Registration

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.