Skip to main content
removed dead link
Source Link
Lester Peabody
  • 4.5k
  • 6
  • 46
  • 81

I have a form with id equal to webform_client_form_3. I have a particular field that I'm altering by applying a class to it like so:

$form['submitted']['estimated_annual_distribution_of_effort']['sensor_technology']['#attributes']['class'][] = 'span1';

This all works great. However, I also need to add a class on to the label for that particular element as well. Looking through the $form array, I haven't been able to find anything that gives access to the labels. Am I just missing something or are the labels not part of the $form array?

UPDATE WITH SOLUTION:

I used Clive's response and took it a step further. My tweak and documentation is a bit long-winded so I created a separate blog post about it here.

I have a form with id equal to webform_client_form_3. I have a particular field that I'm altering by applying a class to it like so:

$form['submitted']['estimated_annual_distribution_of_effort']['sensor_technology']['#attributes']['class'][] = 'span1';

This all works great. However, I also need to add a class on to the label for that particular element as well. Looking through the $form array, I haven't been able to find anything that gives access to the labels. Am I just missing something or are the labels not part of the $form array?

UPDATE WITH SOLUTION:

I used Clive's response and took it a step further. My tweak and documentation is a bit long-winded so I created a separate blog post about it here.

I have a form with id equal to webform_client_form_3. I have a particular field that I'm altering by applying a class to it like so:

$form['submitted']['estimated_annual_distribution_of_effort']['sensor_technology']['#attributes']['class'][] = 'span1';

This all works great. However, I also need to add a class on to the label for that particular element as well. Looking through the $form array, I haven't been able to find anything that gives access to the labels. Am I just missing something or are the labels not part of the $form array?

Updated with link to solution and added webform tag.
Source Link
Lester Peabody
  • 4.5k
  • 6
  • 46
  • 81

I have a form with id equal to webform_client_form_3. I have a particular field that I'm altering by applying a class to it like so:

$form['submitted']['estimated_annual_distribution_of_effort']['sensor_technology']['#attributes']['class'][] = 'span1';

This all works great. However, I also need to add a class on to the label for that particular element as well. Looking through the $form array, I haven't been able to find anything that gives access to the labels. Am I just missing something or are the labels not part of the $form array?

UPDATE WITH SOLUTION:

I used Clive's response and took it a step further. My tweak and documentation is a bit long-winded so I created a separate blog post about it here.

I have a form with id equal to webform_client_form_3. I have a particular field that I'm altering by applying a class to it like so:

$form['submitted']['estimated_annual_distribution_of_effort']['sensor_technology']['#attributes']['class'][] = 'span1';

This all works great. However, I also need to add a class on to the label for that particular element as well. Looking through the $form array, I haven't been able to find anything that gives access to the labels. Am I just missing something or are the labels not part of the $form array?

I have a form with id equal to webform_client_form_3. I have a particular field that I'm altering by applying a class to it like so:

$form['submitted']['estimated_annual_distribution_of_effort']['sensor_technology']['#attributes']['class'][] = 'span1';

This all works great. However, I also need to add a class on to the label for that particular element as well. Looking through the $form array, I haven't been able to find anything that gives access to the labels. Am I just missing something or are the labels not part of the $form array?

UPDATE WITH SOLUTION:

I used Clive's response and took it a step further. My tweak and documentation is a bit long-winded so I created a separate blog post about it here.

Tweeted twitter.com/#!/StackDrupal/status/194835724720287747
Source Link
Lester Peabody
  • 4.5k
  • 6
  • 46
  • 81

Access the label for a form element via hook_form_alter

I have a form with id equal to webform_client_form_3. I have a particular field that I'm altering by applying a class to it like so:

$form['submitted']['estimated_annual_distribution_of_effort']['sensor_technology']['#attributes']['class'][] = 'span1';

This all works great. However, I also need to add a class on to the label for that particular element as well. Looking through the $form array, I haven't been able to find anything that gives access to the labels. Am I just missing something or are the labels not part of the $form array?