form_checkboxes

Versions
4.6
form_checkboxes($title, $name, $values, $options, $description = NULL, $attributes = NULL, $required = FALSE)

Format a set of checkboxes.

Parameters

$title The label for the checkboxes as a group.

$name The internal name used to refer to the buttons.

$values A linear array of keys of the initially checked boxes.

$options An associative array of buttons to display. The keys in this array are button values, while the values are the labels to display for each button.

$description Explanatory text to display after the form item.

$attributes An associative array of HTML attributes to add to each button.

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

Return value

A themed HTML string representing the checkbox set.

Related topics

Code

includes/common.inc, line 1184

<?php
function form_checkboxes($title, $name, $values, $options, $description = NULL, $attributes = NULL, $required = FALSE) {
  if (count($options) > 0) {
    if (!isset($values) || $values == 0) {
      $values = array();
    }
    $choices = '';
    foreach ($options as $key => $choice) {
      $choices .= '<label class="option"><input type="checkbox" class="form-checkbox" name="edit['. $name .'][]" value="'. check_plain($key) .'"'. (in_array($key, $values) ? ' checked="checked"' : ''). drupal_attributes($attributes) .' /> '. $choice .'</label><br />';
    }
    // Note: because unchecked boxes are not included in the POST data, we
    // include a form_hidden() which will be overwritten as soon as there is at
    // least one checked box.
    return form_hidden($name, 0) . theme('form_element', $title, $choices, $description, NULL, $required, _form_get_error($name));
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.