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

Returns HTML for a set of checkbox form elements.

Parameters

$variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #children, #attributes.

Related topics

File

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

Code

function theme_checkboxes($variables) {
  $element = $variables['element'];
  $attributes = array();
  if (isset($element['#id'])) {
    $attributes['id'] = $element['#id'];
  }
  $attributes['class'][] = 'form-checkboxes';
  if (!empty($element['#attributes']['class'])) {
    $attributes['class'] = array_merge($attributes['class'], $element['#attributes']['class']);
  }
  if (isset($element['#attributes']['title'])) {
    $attributes['title'] = $element['#attributes']['title'];
  }
  return '<div' . drupal_attributes($attributes) . '>' . (!empty($element['#children']) ? $element['#children'] : '') . '</div>';
}

Comments

aaronbauman’s picture

If you are trying to apply classes, styles, etc. to a single checkbox of a checkboxes element, there's an undocumented means to do so.

During form building (ie. in your hook_form_alter), create a child element of #type checkbox, and treat it as a standard form element.

For example, this code adds an attributes array to the checkbox "three" from the "my_checkboxes" group:
<?php
function mymodule_form_alter(&$form, &$form_state) {
// Given $form['my_checkboxes'] is #type = 'checkboxes'
// and #options = array(1 => one, 2 => two, 3 => three);
$form['my_checkboxes'][3] = array(
'#type' => 'checkbox',
'#return_value' => 3,
'#default_value' => 3,
'#attributes' => array('class' => array('hidden')),
);
}

aaronbauman’s picture

function mymodule_form_alter(&$form, &$form_state) {
  // Given $form['my_checkboxes'] is #type = 'checkboxes'
  // and #options = array(1 => one, 2 => two, 3 => three);
  $form['my_checkboxes'][3] = array(
    '#type' => 'checkbox',
    '#return_value' => 3,
    '#default_value' => 3,
    '#attributes' => array('class' => array('hidden')),
  );
}