_form_set_class

Versions
5 – 7
_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

▾ 7 functions call _form_set_class()

theme_checkbox in drupal/includes/form.inc
Format a checkbox.
theme_file in drupal/includes/form.inc
Format a file upload field.
theme_password in drupal/includes/form.inc
Format a password field. *
theme_radio in drupal/includes/form.inc
Format a radio button.
theme_select in drupal/includes/form.inc
Format a dropdown menu or scrolling selection box.
theme_textarea in drupal/includes/form.inc
Format a textarea.
theme_textfield in drupal/includes/form.inc
Format a textfield.

Code

drupal/includes/form.inc, line 1590

<?php
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);
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.