0

I have a site with a box on the home page (only) that has a search box. I also have a 'search' link available on all pages of the site, in the navigation. The search link takes the user to a page called 'Search' where the search box appears (again) and allows them to do searches there. I've built the search for that page so the search box appears and the results display only after the user types in a search.

The main question I have is this: how do I create a block for the home page that ONLY displays the search box (results of such search still showing on the results page I've created in Views)?

I know how to expose the View as a block but this doesn't solve my issue because I want the search box itself to still show on the results page too.

1

Consider using a block with php filter to display the exposed search box in a block.

Example below is based on Search API with blocks exposed. I'm taking a guess you're using Search API based on your description.

For Search API:

$view = views_get_view('your_view_here'); $view->set_display('Page'); $view->init_handlers(); $exposed_form = $view->display_handler->get_plugin('exposed_form'); print $exposed_form->render_exposed_form(true);

For Drupal's Core Search:

$block = module_invoke('search', 'block_view'); print render($block['content']);

  • thanks. I'm actually using the basic search.module. Is it possible with that as well? – Sage Mar 25 '15 at 20:47
  • Adjusted answer above to reflect drupal core's search module – webhorse Mar 25 '15 at 20:53
  • thank you kindly; and, I don't mean to keep pestering you with this, but one more thing if you could: if I wanted to reference a 'view' with the drupal core search block code is that possible? (I have a view setup that exposes the search.module filter to users). The view is just called 'Search'. – Sage Mar 25 '15 at 21:15
  • Not entirely sure I understand your question. You can always print any view (block or page). The syntax will be slightly different depending on the type of view. – webhorse Mar 25 '15 at 21:27
  • apologies for miscommunication. The block on my home page that uses the code you gave me for the search form. Right now it allows a user to input content and click search...the results display on another page. that's all good. but the results that are displayed are on the basic search module page I setup, not on the view I setup (a search view that USES the basic search module, but isn't the basic search module itself). The view I'd like the home page block to use for displaying results is a Search view with a Search Terms filter (using the basic search). – Sage Mar 25 '15 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.