2

I'm using answers from Expose a view's filters both in a block, and in the actual view to duplicate an exposed filter as a block and make it appear in another region on every page.

I want to style both form copies a bit differently. When I started to look into the markup, I noticed that I'm getting two forms with identical IDs. Putting aside the styling, that's not good.
The code I am using is the following.

function MYMODULE_block_view($delta = ''){
  $block = array();
  switch($delta){
    case 'mysearch':
      $block['subject'] = t('My Search');
      $block['content'] = _MYMODULE_get_exposed_filter_form(); 
      break;
  }
  return $block;
}

/** Function to get the Exposed filter form **/
function _MYMODULE_get_exposed_filter_form(){
  $view = views_get_view('node_index_view');
  $view->set_display('page');
  $view->init_handlers();
  $exposed_form = $view->display_handler->get_plugin('exposed_form');
  return $exposed_form->render_exposed_form();
}

How do I alter the ID of the copied exposed filter block? If I use hook_form_alter() or hook_form_views_exposed_form_alter() it's going to apply the alteration to both instances.

  • doesnt the block itself have some class / id that could help you distinguish the form for themeing ? – mojzis Jun 15 '12 at 18:38
  • Theming is not a problem. A document should not have two identical IDs. IDs should be unique. – Artur Jun 15 '12 at 18:55
0

This issue was discussed and answered in this thread, it includes a patch to fix the issue:

https://www.drupal.org/node/1735096

Another option is to use the module MEFIBS - More exposed forms in blocks

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.