Definition

form_checkboxes($title, $name, $values, $options, $description = NULL, $attributes = NULL, $required = FALSE)
drupal-4-6/includes/common.inc, line 1184

Description

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.

Code

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));
  }
}