Trying to programmatically alter the id of an exposed filter in views This is for Drupal 7.

I am trying to modify an exposed filter's id in views. Basically we've noticed a use-case with multiple simple hierarchical selects on a given page, in separate exposed filter forms will conflict because they're using the same id attribute in the HTML.

The solution we've come up to to solve this is to append a short hash to the end of this id, making it unique across the page.

The problem is that I'm having trouble figuring out exactly where to do this, and the views objects' immense size doesn't help me in tracking down exactly where I have to make this change.

I'm trying things like this (this is in hook_views_pre_view):

$view-&gt;display['DISPLAY_NAME']-&gt;handler-&gt;options['filters']['field_FIELD_NAME_HASH-HERE'] = $view-&gt;display['DISPLAY_NAME']-&gt;handler-&gt;options['filters']['FIELD_NAME'];

$view-&gt;display['DISPLAY_NAME']-&gt;handler-&gt;options['filters']['field_FIELD_NAME_HASH-HERE']['expose']['identifier'] = 'field_FIELD_NAME_HASH-HERE';

$view-&gt;display['DISPLAY_NAME']-&gt;handler-&gt;options['filters']['field_FIELD_NAME']['expose']['operator_id'] = 'field_FIELD_NAME_HASH-HERE_op';


However this only seems to throw an error.

So how do I change the id on a given exposed filter for a view/display?

EDIT - this is the markup I am trying to affect:

&lt;div class="form-item form-type-select form-item-field-FIELD_NAME shs-wrapper-processed"&gt;
 &lt;select class="element-invisible shs-enabled form-select shs-processed" id="edit-field-FIELD_NAME" name="field_FIELD_NAME" style="display: none;"&gt;&lt;option value="All" selected="selected"&gt;&lt;option&gt;&lt;/option&gt;&lt;/select&gt;
&lt;select id="edit-field-FIELD_NAME-select-1" class="shs-select form-select shs-select-level-1 chosen-disable" style="display: inline-block;"&gt;&lt;option&gt;&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;


Everywhere that has FIELD_NAME either has the default field name, or if I change it in Views, the changed identifier, however I can't seem to change any of these names programmatically - even with the answer below, which is what I really need to do.

How do I affect this markup?

Here is my current hook_preprocess_views_exposed_form:

if($vars['form']['#id'] == 'views-exposed-form-reference-views-block-1') {
    $number = &lt;NUMBERHERE&gt;;
    $vars['form']['#info']['filter-field_FIELD_NAME']['value'] = 'field_FIELD_NAME_' . $number;
    $vars['form']['field_FIELD_NAME_' . $number] = $vars['form']['field_FIELD_NAME'];
    $vars['form']['field_FIELD_NAME_' . $number]['#id'] = 'edit-FIELD-NAME-' . $number;
    $vars['form']['field_FIELD_NAME_' . $number]['#parents'] = array('field_FIELD_NAME_' . $number);
    $vars['form']['field_FIELD_NAME_' . $number]['#array_parents'] = array('field_FIELD_NAME_' . $number);
    $vars['form']['field_FIELD_NAME_' . $number]['#name'] = 'field_FIELD_NAME_' . $number;
    $vars['widgets']['filter-field_FIELD_NAME']-&gt;id = 'edit_field_FIELD-NAME-' . $number;
    unset($vars['form']['field_FIELD_NAME']);
  }
I think you might be using the wrong tool for the job. It sounds like this is a theming problem, not a views data structure problem (which would use something like hook_views_pre_view().

You can override the template views-exposed-form.tpl.php to override the markup of the exposed form &amp; the preprocess function template_preprocess_views_exposed_form() to override the markup form widgets:

function MYTHEME_preprocess_views_exposed_form(&amp;$vars, $hook) {
  // @TODO: alter markup of $vars['widgets']['filter-MYFILTER']-&gt;widget.
}


Alternatively, the views UI provides a means to change the id element by changing the Filter identifier underneath the More fieldset which also changes the URL query parameter used as well.