Change that Form Element - Give a fieldset a class

I looked for this a few times and didn't find it so I decided to write a quick blog post for future themers to discover. You see Drupal is full of forms and fields. There are any number of reasons that you may want an element on a form to be identified by a unique class or ID. I ran into this today when I wanted to theme a fieldset, provided by a module, that didn't have a class on the fieldset. Now there are many ways to theme a fieldset by using the divs that contain the fieldset. However, sometimes it's nice to just have a theme set for a fieldset, and apply that class when and where you need it.
Here is the basic syntax you are looking for is when using hook_form_alter.
$form['subscriptions']['#attributes'] = array('class' => 'subscription-set');
The whole thing would look something like this.
function [NAME-OF-MODULE]_form_alter(&$form, &$form_state, $form_id) {
$form['subscriptions']['#title'] = NULL;
$form['subscriptions']['#attributes'] = array(
'class' => 'subscription-set');
}
Happy Theming!

Comments
You should really wrap your
Good Point, My Final Result Is Actually
Add new comment