Hi,

I'm trying to display the Views Fast Search search box on my front page (and other non-views pages).

In views I enabled views_fastsearch and made it a block, but when I insert the block into a region it doesn't display anything.

How do I search using Views Fast Search when not on a views page? Ideally I'd like to insert it across all pages as a block. Any assistance is appreciated.

Thanks,
Michael

Comments

jimmb’s picture

Assigned: Unassigned » jimmb

I'm trying to do the same thing, only with a view that's also set up as a page. The exposed filter is the search element, which you can see here: http://mcbw.sundaysenergy.org/mnservicessearch

I believe it should be possible to have a page view of search results, but to have the search function be both on a page and a separate block..... If so, I'll be glad to hear the answer! Right now, when I try to set it up I get the same result that burtrito mentions.

Thanks,

Jim

allie micka’s picture

I got this to work by overriding the standard search block's form:


function mymodule_form_alter($form_id, $form) {
  // Use a view for the main site search.
  if ($form_id == 'search_block_form') {
    $form['#action'] = url('directory_search');
    $form['#method'] = 'get';
    $form['search_block_form_keys']['#name'] = 'filter0';
  }
}

This will grab the search block form as it goes by, updating its URL and parameters to point to my view instead. Besure to replace "directory_search" with the URL of your search view.

burtrito’s picture

Hi Allie,

Add that code to my theme's Template.php file?

Do I need to change anything else other than 'directory_search' ?

Thanks,
Mike

dejbar’s picture

Category: support » bug

Given that a block is actually created that doesn't work I think this should be regarded as a bug instead of a support request. Perhaps if the documentation explained that you shouldn't expect the generated block to work this would become a feature request.

As for Allie's solution. I tried adding this function to template.php renaming it from 'mymodule_form_alter' to 'theme_form_alter' (this has appeared to work in the past) but there was no effect. Is this how it was expected to be used? I think that most people who don't know how to solve this problem probably won't know what to do with that code.

doc2@drupalfr.org’s picture

Allie, mogtofu, could you explain a bit more what to change and where?

The question is about overriding the search bar which appears at the top right corner. I guess this is not about adding a block. But if we need such a block to use its form elements, where all of that will go?

Many thanks people!

mogtofu’s picture

Another simple way is just to create a new block, and using full html format you make your own little form :

<form id="views-filters" method="get" action="search/fast">
  <div class="form-item">
     <input type="text" class="form-text" size="10" id="edit-filter0" name="filter0" maxlength="255"/>
     <input type="submit" class="form-submit" value="Search" id="edit-submit"/>
  </div>
</form>
mroswell’s picture

mogtofu, thanjks for a terrific solution. I offer one amendment: I added a forward slash before the search/fast in the form tag.

<form id="views-filters" method="get" action="/search/fast">
  <div class="form-item">
     <input type="text" class="form-text" size="10" id="edit-filter0" name="filter0" maxlength="255"/>
     <input type="submit" class="form-submit" value="Search" id="edit-submit"/>
  </div>
</form>
doc2@drupalfr.org’s picture

Status: Active » Closed (duplicate)