Skip to main content
Post date:
Friday, July 20, 2012

This is a PHP function I wrote that helps simulating a drupal get form for Views Exposed Filters, it returns the exposed form array so you can theme it or alter it:

function _get_exposed_form($view, $display_id){
  $view = views_get_view($view);
  $view->set_display($display_id);
  $view->init_handlers();
  $form_state = array(
    'view' => $view,
    'display' => $view->display_handler->display, 
    'exposed_form_plugin' => $view->display_handler->get_plugin('exposed_form'),
    'method' => 'get',
     'rerender' => TRUE,
     'no_redirect' => TRUE,
   );
   $form = drupal_build_form('views_exposed_form', $form_state);
   $form_redered = drupal_render($form);
	
   return $form_rendered;
}

I took this idea from the views/plugins/views_plugin_exposed_form.inc::render_exposed_form method.

Hope it helps!

Add new comment
The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Related Blogs