I am trying to add a taxonomy dropdown to my sites basic search form. I was thinking I could use hook form alter to to add a taxonomy dropdown to it, and then change the validate and submit functions to the ones used by advanced search. I am unfamiliar enough with the forms API that I could be making a huge mistake.

function taxonomy_basic_search_form_alter($form_id, &$form){

	if($form_id == 'search_theme_form' || $form_id == 'search_block_form'){
	 
	 if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
      $form['basic']['inline']['category'] = array(
        '#type' => 'select',
        '#prefix' => '<div class="criterion">',
        '#size' => 1,
        '#suffix' => '</div>',
        '#options' => $taxonomy,
        '#multiple' => FALSE,
      );
    }
	$form['#validate'] = array('search_form_validate' => array($form_id, $form_values, $form));
      $form['#submit'] = array('search_form_submit' => array($form_id, $form_values));

	}

}

With this in a quick module I made, the the taxonomy dropdown shows up but when I hit search I get errors:

* warning: array_shift() [function.array-shift]: The argument should be an array in /var/www/vhosts/concordmonitor.info/httpdocs/classifieds/includes/form.inc on line 854.
* Please enter some keywords.

To be honest, I'm not even sure the advanced search and normal search use different validationa and submission functions. If I dont try to override those, the search works, except it ignores what I select for taxonomy.

I will be very grateful for any help.

Comments

TPerkins’s picture

I ended up making a View called Search, and exposing the Search:index and Taxonomy filters.

It works well.

kosmik’s picture

TPerkins.

Could you provide step-by-step details how you did it. I am new to view and cck. I wanted to provide dropdown search based on taxonomy terms.

Thanks.

tachikoma5’s picture

Here is a step-by-step details for search field using views filters

http://acquia.com/blog/s-files-adding-search-fields-and-filters-views

If you want to modify the search box form it can be done.
see http://www.cnngo.com/
http://buytaert.net/cnn-using-drupal

But I have not seen a good step-by-step guide on how cnngo.com modified the forms and got it to work with the drupal search framework.

The following article might get you started.
http://acquia.com/blog/drupals-search-framework-the-execution-a-search
and "eddy de boer" posted a draft of code, he is trying to get a drop-down-box for content types.
http://acquia.com/blog/drupals-search-framework-the-execution-a-search#c...

More search stuff.
http://robshouse.net/article/views-3-apache-solr-acquia-drupal-future-se...

kosmik’s picture

I could not find a workable solution to my need for a drop-down taxonomy search..

I finally settled for a simpler answer i.e. I got to display taxonomy/category listing using "sitemenu" module. I am quite happy at least I have something..see example here: http://themesis.com

anandchawra’s picture

Hello,

I need some help from you. My requirement is a bit different, shall be great if you can guide me step by step.

I have a defined vocabulary, which has about 10 Terms (main categories) and each of those 10 terms has 8-10 child terms as well (sub categories). Many of these child terms - at times have sub-sub categories too.

Finally when it comes to the deepest levels - there are many articles (stories / pages) - associated to the deepest term.

What I want to achieve is:

1. A block which has two drop down boxes. From the first box - the user selects 1/10 terms (main categories), the sub-categories then get dynamically updated and in the second box - the user selects the 1/10 related sub category and hits submit (ignoring further sub categories). On enter, a list of all nodes which match these criteria should be displayed.

2. I want a [page in grid format] on the main page (4 x4) small boxes or panes. Each grid would have an image (for the Category) and the Main category (parent term) - linked to node and then below it a list of top 3 sub-categories (linked to node) and a more... button.

For a graphic explanation - You can look at Lynda.com. On the home page they have these filtered search for courses. This is what I need for requirement 1.

I have been trying various approaches and have not got the desired result. A way out was to create a menu for taxonomy.. which I have already done, but this is not what I want to achieve.

Would you be able to teach me how to achieve this ??? It will be a great learning experience.

Thankx