form_checkboxes($title, $name, $values, $options, $description = NULL, $attributes = NULL, $required = FALSE)
drupal/includes/common.inc, line 1184
Format a set of checkboxes.
$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.
A themed HTML string representing the checkbox set.
| Name | Description |
|---|---|
| Form generation | Functions to enable output of HTML forms and form elements. |
| Input validation | Functions to validate user input. |
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));
}
}