Skip to main content

Displaying exposed filter form for views in Drupal 6 (views 2)

An article from ComputerMinds - Building with Drupal in the UK since 2005
15th Aug 2008

Mike Dixon

Senior Mind
Mike Dixon
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

One of the joys of working with Drupal 6, and views 2, is that you have to relearn a lot of things you used to take for granted ... one trick we use in most projects is embedding views filters in blocks, nodes or custom code. There are plenty of scenarios this is useful, the classic being to create a flexible views based replacement for the normal Drupal search. Anyway, enough of the blurb - heres the good stuff - some code to give you the filter form for a Drupal 6 views 2 view.


  $view = views_get_view('your_view_name');
  $view->set_display('default');
  $view->init_handlers();
  $form_state = array(
    'view' => $view,
    'display' => $view->display_handler->display,
    'method' => 'get',
    'rerender' => TRUE,
    'no_redirect' => TRUE,
  );
  $output = drupal_build_form('views_exposed_form', $form_state);
  return $output;

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.