_form_set_class

  1. drupal
    1. 5
    2. 6
    3. 7
    4. 8
Versions
5 – 8 _form_set_class(&$element, $class = array())

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

▾ 8 functions call _form_set_class()

theme_checkbox in includes/form.inc
Returns HTML for a checkbox form element.
theme_fieldset in includes/form.inc
Returns HTML for a fieldset form element and its children.
theme_file in includes/form.inc
Returns HTML for a file upload form element.
theme_password in includes/form.inc
Returns HTML for a password form element.
theme_radio in includes/form.inc
Returns HTML for a radio button form element.
theme_select in includes/form.inc
Returns HTML for a select form element.
theme_textarea in includes/form.inc
Returns HTML for a textarea form element.
theme_textfield in includes/form.inc
Returns HTML for a textfield form element.

Code

includes/form.inc, line 4014

<?php
function _form_set_class(&$element, $class = array()) {
  if (!empty($class)) {
    if (!isset($element['#attributes']['class'])) {
      $element['#attributes']['class'] = array();
    }
    $element['#attributes']['class'] = array_merge($element['#attributes']['class'], $class);
  }
  // This function is invoked from form element theme functions, but the
  // rendered form element may not necessarily have been processed by
  // form_builder().
  if (!empty($element['#required'])) {
    $element['#attributes']['class'][] = 'required';
  }
  if (isset($element['#parents']) && form_get_error($element)) {
    $element['#attributes']['class'][] = 'error';
  }
}
?>