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.
Comment | File | Size | Author |
---|---|---|---|
#4 | form_checkboxes_0.patch | 4.93 KB | Anonymous (not verified) |
form_checkboxes.patch | 1.3 KB | jhriggs | |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedCheckboxes are often a superior replacement for a multi-select dropdown. +1
Comment #2
Dries CreditAttribution: Dries commentedI'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.
Comment #3
Dries CreditAttribution: Dries commentedAwaiting extended patch. Marking this 'active'.
Comment #4
(not verified) CreditAttribution: commentedHere'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.
Comment #5
Dries CreditAttribution: Dries commentedCommitted to HEAD. Thanks.
Comment #6
(not verified) CreditAttribution: commented