I try to limit number of content types in the basic search box and can't get it to work. It still returns everything to me. Is it because I am using "search-theme-form" and the filtering only works in "search-form". I went through the threads but was confused even further by the difference in Drupal 5 and 6. I am themeing the basic search box in my own search-theme-form.tpl.php and here is the generated HTML codes for the search box.

Essentially, I added the last line to allow search only for my content type called "page_content" but it is not working.

<form action="/homepage"  accept-charset="UTF-8" method="post" id="search-theme-form">
<div>
        <div class="form">
                <input type='text' class='text' name='search_theme_form' id='edit-search-theme-form-1' value='Search Text'/>
                <input type='image' class='button' name='op' id='edit-submit' src='/sites/all/themes/my-style1/images/go-button.gif'/>
                <input type="hidden" name="form_build_id" id="form-f754c85cb95740deeaa827f49dd79982" value="form-f754c85cb95740deeaa827f49dd79982"  />
                <input type="hidden" name="form_id" id="edit-search-theme-form" value="search_theme_form"  />
                <input type="hidden" name="type[page_content]" id="edit-type-page_content" value="page_content" />	
        </div>
</div>
</form>

Comments

arnoldc’s picture

Bump. Anyone?

arnoldc’s picture

Okay, two issues I think.

1. search_theme_form probably doesn't take the extra fields so I have to resort to use either search_block_form or search_form.
2. make sure to grant "use advanced search" permission or the search won't work.

So add this form to your template and it should do the trick. In this example, search in "page_content" and "news_article" types only.

<form action="/search/node" method="post" id="search-block-form" class="search-form">
  <input type='text' class='text' value="" name='keys' />
  <input type='image' class='button' name='op' id='edit-submit' src="<?php print base_path().path_to_theme(); ?>/images/go-button.gif" />  
  <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[page_content]" id="edit-type-page_content" value="page_content" /> 
  <input type="hidden" name="type[news_article]" id="edit-type-news_article" value="news_article" /> 
</form>

Now I have to figure out how to add Taxonomy filtering in the form. I couldn't figure out what to put in the form based on advanced form or is it possible at all. Anyone?

I am surprised Drupal's core search is not very flexible and not so easy to customize.....

arnoldc’s picture

Okay, may not be pretty but got it to work.

By placing the following simple search box in my page template, I can search contents by my specific content types and categories. Do not use search_theme_form as it doesn't work with advanced search functions.

  <form action="/search/node" method="post" id="search-block-form" class="search-form">
    <input type='text' class='text' value="" name='keys' />
    <input type='image' class='button' name='op' id='edit-submit' src="<?php print base_path().path_to_theme(); ?>/images/go-button.gif" />  
    <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[page_content]" id="edit-type-page_content" value="page_content" /> 
    <input type="hidden" name="type[news_article]" id="edit-type-news_article" value="news_article" /> 
    <select name="category[]" multiple="multiple"  class="form-select" id="edit-category" size="10" style="display:none;">
    	<option selected value="<?php print $_COOKIE['site_location']; ?>">user location</option>
    </select>  
  </form>
ha5bro’s picture

Doesn't seem to jive for me when I'm not logged in. Boo-urns.

J

ha5bro’s picture

My bad -- this was a simple conflict with Search Config module.

J

Dret’s picture

I have the same problem the snippet above works fine when I'm logged but not for Anonymus user.

Have I to set "advance search" for all users?

submit.dk’s picture

The same problem here. Doesn't work for anonymous user.

http://www.submit.dk/drupal

Dret’s picture

Solved with Search Config module