theme_form_element

Definition

theme_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE)
drupal/includes/theme.inc, line 554

Description

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

Namesort iconDescription
Themeable functionsFunctions that display HTML, and which can be customized by themes.

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;
}