theme_form_element

Versions
4.6 – 4.7
theme_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE)
5 – 6
theme_form_element($element, $value)
7
theme_form_element($variables)

Theme a form element.

Parameters

$variables An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #title, #description, #id, #required, #children

Return value

A string representing the form element.

Related topics

Code

includes/form.inc, line 2799

<?php
function theme_form_element($variables) {
  $element = $variables['element'];
  // This is also used in the installer, pre-database setup.
  $t = get_t();

  // Add element's #type and #name as class to aid with JS/CSS selectors.
  $class = array('form-item');
  if (!empty($element['#type'])) {
    $class[] = 'form-type-' . strtr($element['#type'], '_', '-');
  }
  if (!empty($element['#name'])) {
    $class[] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
  }

  $output = '<div class="' . implode(' ', $class) . '">' . "\n";
  $required = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : '';

  if (!empty($element['#title']) && empty($element['#form_element_skip_title'])) {
    $title = $element['#title'];
    if (!empty($element['#id'])) {
      $output .= ' <label for="' . $element['#id'] . '">' . $t('!title !required', array('!title' => filter_xss_admin($title), '!required' => $required)) . "</label>\n";
    }
    else {
      $output .= ' <label>' . $t('!title !required', array('!title' => filter_xss_admin($title), '!required' => $required)) . "</label>\n";
    }
  }

  $output .= " " . $element['#children'] . "\n";

  if (!empty($element['#description'])) {
    $output .= ' <div class="description">' . $element['#description'] . "</div>\n";
  }

  $output .= "</div>\n";

  return $output;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.