So I was just putting together a form with several checkboxes (apparently something I haven't done too much of in Drupal), and imagine my surprise when I found there was no form_checkboxes() function to complement checkboxes as form_radios() does radio buttons!

The attached patch does just that: create form_checkboxes(). It is used the same as form_radios() except that the third argument, $values, is expected to be an array of checked values. The name of the checkbox input items will result in an array, so a form submitted using checkboxes named "my_checks" will result in $_POST['edit']['my_checks'], which is an array of the checked values.

CommentFileSizeAuthor
#4 form_checkboxes_0.patch4.93 KBAnonymous (not verified)
form_checkboxes.patch1.3 KBjhriggs
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

Checkboxes are often a superior replacement for a multi-select dropdown. +1

Dries’s picture

I'm OK with this patch but I'd like to update existing code where possible. That would help evaluate this patch. For example, the block settings on the user account pages, could probably benefit from the proposed function.

Dries’s picture

Awaiting extended patch. Marking this 'active'.

Anonymous’s picture

FileSize
4.93 KB

Here's a updated patch with two other module changes as examples.
- user.module - user account roles selection
- taxonomy.module - vocabulary node types

Still undecided whether this is actually a usability improvement.

Dries’s picture

Committed to HEAD. Thanks.

Anonymous’s picture