Same name and namespace in other branches
  1. 4.7.x includes/theme.inc \theme_form_element()
  2. 5.x includes/form.inc \theme_form_element()
  3. 6.x includes/form.inc \theme_form_element()
  4. 7.x includes/form.inc \theme_form_element()

Return a themed form element.

Parameters

$title the form element's title:

$value the form element's data:

$description the form element's description or explanation:

$id the form element's ID used by the <label> tag:

$required a boolean to indicate whether this is a required field or not:

$error a string with an error message filed against this form element:

Return value

a string representing the form element

Related topics

11 theme calls to theme_form_element()
filter_form in modules/filter.module
Generate a selector for choosing a format in a form.
form_checkbox in includes/common.inc
Format a checkbox.
form_checkboxes in includes/common.inc
Format a set of checkboxes.
form_file in includes/common.inc
Format a file upload field.
form_item in includes/common.inc
Format a general form item.

... See full list

File

includes/theme.inc, line 554
The theme system, which controls the output of Drupal.

Code

function theme_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {
  $output = "<div class=\"form-item\">\n";
  $required = $required ? '<span class="form-required">*</span>' : '';
  if ($title) {
    if ($id) {
      $output .= " <label for=\"{$id}\">{$title}:</label>{$required}<br />\n";
    }
    else {
      $output .= " <label>{$title}:</label>{$required}<br />\n";
    }
  }
  $output .= " {$value}\n";
  if ($description) {
    $output .= " <div class=\"description\">{$description}</div>\n";
  }
  $output .= "</div>\n";
  return $output;
}