Getting the value of a checkbox in form api I'm creating a form using Drupal's form API.  This form includes about 50 or so checkboxes that I'm creating using the type 'checkbox'.  The checkboxes are grouped using several fieldset elements.  The checkbox is created from a look using an XML file that decides what checkboxes will appear.  

$ageKey = '08';
$course = 'y';

$form['events'][$ageKey][$course] = array(
  '#type' =&gt; 'fieldset',
  '#title' =&gt; 'Set of checkboxes'
}

foreach($xCourse-&gt;event as $event) {
  $eventKey = (int)$event['distance'] .'-' . (int)$event['event'];
  $form['events'][$ageKey][$course][$ageKey . ' ' . $course . ' ' . $eventKey] = array(
    '#type' =&gt; 'checkbox',
    '#title' =&gt; (int)$event['distance'] . ' ' . $top5-&gt;dispStroke((int)$event['stroke']),
    '#default_value' =&gt; 1,
  );
}


I'm using hook_submit to process the form

function import_form_submit($form, &amp;$form_state) {
  $checkboxes = $form_state['values'];

  //do stuff here
}


However, I find that the value for all my checkboxes is 0, regardless if the checkbox was unchecked by me or not.  If I remove '#default_value' =&gt; 1 from the checkbox definition, none of the checkboxes are checked by default.  The values array also appears to ignore the hierarchy I set up.  

How do I get the checked state of the checkbox in my submission code? What am I missing here?
I found the answer.  I added '#tree' =&gt; TRUE, to the fieldset and suddenly things are working correctly.  I think because of the eventKeys were repeated so overwriting others. By adding the tree attribute, all the checkboxes were seperated into their respective fieldsets in the $form_state['values'] array.