form_checkbox

Format a checkbox.

Parameters

$title: The label for the checkbox.

$name: The internal name used to refer to the button.

$value: The value that the form element takes on when selected.

$checked: Whether the button will be initially selected when the page is rendered.

$description: Explanatory text to display after the form item.

$attributes: An associative array of HTML attributes to add to the button.

$required: Whether the user must check this box before submitting the form.

Return value

A themed HTML string representing the checkbox.

Related topics

26 calls to form_checkbox()

File

includes/common.inc, line 1153
Common functions that many Drupal modules will need to reference.

Code

function form_checkbox($title, $name, $value = 1, $checked = FALSE, $description = NULL, $attributes = NULL, $required = FALSE) {
  $element = '<input type="checkbox" class="' . _form_get_class('form-checkbox', $required, _form_get_error($name)) . '" name="edit[' . $name . ']" id="edit-' . $name . '" value="' . check_plain($value) . '"' . ($checked ? ' checked="checked"' : '') . drupal_attributes($attributes) . ' />';
  if (!is_null($title)) {
    $element = '<label class="option">' . $element . ' ' . $title . '</label>';
  }
  // Note: because unchecked boxes are not included in the POST data, we include
  // a form_hidden() which will be overwritten for a checked box.
  return form_hidden($name, 0) . theme('form_element', NULL, $element, $description, $name, $required, _form_get_error($name));
}
Login or register to post comments