theme_checkbox
- Versions
- 4.7 – 6
theme_checkbox($element)- 7
theme_checkbox($variables)
Theme a checkbox form element.
Parameters
$variables An associative array containing:
- element: An associative array containing the properties of the element. Properties used: #title, #value, #return_value, #description, #required, #attributes.
Return value
A themed HTML string representing the checkbox.
Related topics
Code
includes/form.inc, line 2139
<?php
function theme_checkbox($variables) {
$element = $variables['element'];
$t = get_t();
_form_set_class($element, array('form-checkbox'));
$checkbox = '<input ';
$checkbox .= 'type="checkbox" ';
$checkbox .= 'name="' . $element['#name'] . '" ';
$checkbox .= 'id="' . $element['#id'] . '" ' ;
$checkbox .= 'value="' . $element['#return_value'] . '" ';
// Unchecked checkbox has #value of numeric 0.
if ($element['#value'] !== 0 && $element['#value'] == $element['#return_value']) {
$checkbox .= 'checked="checked" ';
}
$checkbox .= drupal_attributes($element['#attributes']) . ' />';
if (isset($element['#title'])) {
$required = !empty($element['#required']) ? ' <span class="form-required" title="' . $t('This field is required.') . '">*</span>' : '';
$checkbox = '<label class="option" for="' . $element['#id'] . '">' . $checkbox . ' ' . $element['#title'] . $required . '</label>';
}
return $checkbox;
}
?>Login or register to post comments 