In an attempt to get a checkbox selection on a filter form, I needed to handle an array of arrays which turned out to be a grouping of selections.
The top level array is, of course, the array of the box groups. And, each array element is a list of checkboxes.
This turns out to be a group originally targeted at a selection list (). But, there is sometimes a need to turn a single selection into a multiple one.
In this case, changing form API code by transforming '#type' => "select" into '#type' => 'checkboxes'.
So, I thought maybe the checkboxes could be grouped into field lists. (This works for one application.) Of course, there is perhaps a better way. I have been using OAT during the last few weeks. And, they can make a tree, or nested UL lists, into expandable and collapsible checkbox trees. So, now I am wondering how to make that work with this form API.
In the mean time, the following solved one problem and integrates well with the form api. This change is made in form.inc:
function expand_checkboxes($element) {
$value = is_array($element['#value']) ? $element['#value'] : array();
$element['#tree'] = TRUE;
if (count($element['#options']) > 0) {
if (!isset($element['#default_value']) || $element['#default_value'] == 0) {
$element['#default_value'] = array();
}