I would like to render a views exposed filter block in my node theme. This is what I am doing:

function MYTHEME_preprocess_node(&$vars) {
   $search_form = drupal_get_form('views_exposed_form');
   $search_box = drupal_render($search_form);
   $vars['search_box'] = $search_box;

This way I could simply add variable $search_box into my theme and the filter block would be displayed.

I have confirmed and 'views_exposed_form' is the correct form_id. The problem is that this is throwing a nasty error that doesn't log the error message. My template gets broken (still appears, but broken) and no error message is logged.

It does work if I try to display, let's say, a regular search box. The code is the same, all I have to do is change to the search block form id (search_form) like this:

$search_form = drupal_get_form('search_form');

Right now, I am almost pulling my hair, have searched up and down the web. Any help is appreciated. Thank you!

1 Answer 1


You're actually having an error if you check the php logs:

PHP Fatal error:  Call to a member function get_exposed_input() on a non-object in   
.../sites/all/modules/views/views.module on line 1950

You can't just call drupal_get_form('views_exposed_form') because drupal wouldn't know which exposed form you want to render. Remember that a view or view display have its own exposed form.

If you check where the error is, you'll see that it's caused by not having a view object in the form_state variable.

What I suggest you do is use the Admin Block UI (/admin/structure/block) and just restrict which node types where you want to display the exposed filter.

  • Thank you very much, Pax. I have decided to take another approach into this problem, but your explanation helped me find a better track. Commented Sep 10, 2013 at 1:03
  • Hi Marcos, can you explain your different approach. I have the same situation currently here.
    – Justme
    Commented May 19, 2017 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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