I have a Views exposed filter, for which I am trying to add a class via hook_form_alter() with the following code:

$form['price']['#attributes'] = array('class' => array('price-hide'));

Outputting the form array with devel shows that this is adding the attribute fine; however I can only assume there is another hook_form_alter() running after my module that is wiping my attributes, as other attributes are being added, and mine never make it to the HTML output.

I've tried moving from hook_form_alter() to hook_form_views_exposed_form_alter() since I remember that hook running at a different time than hook_form_alter(); however, this doesn't seem to make any difference.

1 Answer 1


Did you check the actual markup after the page is rendered with Firebug or something to see for sure if another module's hook_form_alter() is overriding yours? If that is indeed the case then an easy way to get around is it by increasing your module's weight so hook_form_alter() in your module is called after other modules.

db_query("UPDATE {system} SET weight = 20 WHERE name = 'my_module'");

EDIT: I should say that this code should go in hook_install() and you should then reinstall your module to get the weight set properly.

  • I was afraid this might be the problem. I'm only using what you might call "middle of the road" modules, which I was hoping would play safe with overriding #attributes and not redeclare. Thanks I'll try this.
    – DanH
    Aug 26, 2011 at 8:18

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.