4.7.x form.inc theme_checkbox($element)
5.x form.inc theme_checkbox($element)
6.x form.inc theme_checkbox($element)
7.x form.inc theme_checkbox($variables)

Returns HTML for a checkbox form element.


$variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #id, #name, #attributes, #checked, #return_value.

Related topics

1 theme call to theme_checkbox()
system_element_info in modules/system/system.module
Implements hook_element_info().


includes/form.inc, line 3223
Functions for form and batch generation and processing.


function theme_checkbox($variables) {
  $element = $variables['element'];
  $element['#attributes']['type'] = 'checkbox';
  element_set_attributes($element, array(
    '#return_value' => 'value',

  // Unchecked checkbox has #value of integer 0.
  if (!empty($element['#checked'])) {
    $element['#attributes']['checked'] = 'checked';
  _form_set_class($element, array(
  return '<input' . drupal_attributes($element['#attributes']) . ' />';


amagdy’s picture

I got tricked to use the following structure

$variables = array( '#title' => 'some title',
'#attributes' => array(
'class' => array('handle-applicant', "paid-$sid"),
'sid' => $sid,
'field' => 'paid'))

I didn't notice the it is an associative array of associative array, quite frankly, i don't understand why

$variables = array('element' => array( '#title' => 'some title',
'#attributes' => array(
'class' => array('handle-applicant', "paid-$sid"),
'sid' => $sid,
'field' => 'paid'))

theme('checkbox', $variables);

blake.wall’s picture

I believe the reason they do that is because it is flexible. If they want to add another field into the variables array, it's easy to do. You could easily write:

$variables = array();
$variables['element'] = $someElement;
$variables['another_element'] = $anotherElement;

as long as you're talking about an array of arrays.

arnoldbird’s picture

It's not clear if theme_checkbox works as documented, and it doesn't seem to be in wide use. The function does not seem to be in use anywhere in Drupal's 7.x core. At least it's not found if you grep for 'theme_checkbox' or "theme('checkbox" -- you'll find only the function definition itself.

These properties mentioned in the documentation don't have any effect on the output: #title, #value, #description. Initially, I'm not sure why the documentation mentions these properties.

The #attributes property does work, so you can set a value like so...

$variables['element']['#attributes']['value'] = '123';