Change that Form Element - Give a fieldset a class
04 Feb
Posted by webthingee
in code, drupal, php, theme
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.
Happy Theming!
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
if ( $form_id == 'foo') { // make your modifications for the foo form. } elseif ($form_id == 'bar') { // make your modifications for the bar form. }Hmmm, your input format doesn't handle code very well.Good Point, My Final Result Is Actually
function [MYTHEMENAME]_form_alter(&$form, &$form_state, $form_id) {
//dsm($form_id);
//dsm($form);
switch ($form_id) {
// Views Exposed Filters
case 'views_exposed_form':
$form['submit']['#value'] = t('Go For It'); // default is 'apply'
break;
// Node Edit Form
case 'node_type_form':
// Allow Content Body Titles to be 400 characters.
$form['submission']['body_label']['#maxlength'] = 200;
break;
}
}
This way I just keep adding, and adding, and adding....
Branda
louis vuitton
Post new comment