You are here

function _form_set_class in Drupal 6

Same name and namespace in other branches
  1. 4 includes/form.inc \_form_set_class()
  2. 5 includes/form.inc \_form_set_class()
  3. 7 includes/form.inc \_form_set_class()

Sets a form element's class attribute.

Adds 'required' and 'error' classes as needed.

Parameters

&$element: The form element.

$name: Array of new class names to be added.

Related topics

7 calls to _form_set_class()
theme_checkbox in includes/form.inc
Format a checkbox.
theme_file in includes/form.inc
Format a file upload field.
theme_password in includes/form.inc
Format a password field.
theme_radio in includes/form.inc
Format a radio button.
theme_select in includes/form.inc
Format a dropdown menu or scrolling selection box.

... See full list

File

includes/form.inc, line 2364

Code

function _form_set_class(&$element, $class = array()) {
  if ($element['#required']) {
    $class[] = 'required';
  }
  if (form_get_error($element)) {
    $class[] = 'error';
  }
  if (isset($element['#attributes']['class'])) {
    $class[] = $element['#attributes']['class'];
  }
  $element['#attributes']['class'] = implode(' ', $class);
}