Accessible Checkboxes Using Drupal's Form API Im trying to get a set of checkboxes produced via Drupal's form api to pass the WCAG AA accessibility standards, the problem i am facing is with regard to labels and for attributes.

For example i am returning the following form definition via a hook_block_view(), i cant use drupal_get_form as normal as i dont want a form element wrapping the output which means i lose some of the processing that drupal_get_form does which is why i have to add in form_process_checkboxes and am missing some other functionality that gives the individual checkboxes their ID's(which is then used as the for attribute)

$form['tests_taken'] = array(
  '#type' =&gt; 'checkboxes',
  '#options' =&gt; drupal_map_assoc(array(t('SAT'), t('ACT'))),
  '#title' =&gt; t('What standardized tests did you take?'),
   '#attributes' =&gt; array(
     'name' =&gt; 'example-checkboxes[]'
   )
);


$form['tests_taken'] = form_process_checkboxes($form['tests_taken']);

dsm($form);

return $form;


This produces the following markup.

&lt;div class="form-checkboxes"&gt;&lt;div class="form-item form-type-checkbox"&gt;
    &lt;input name="example-checkboxes[]" type="checkbox" value="SAT" class="form-checkbox"&gt; 
&lt;label class="option"&gt;SAT &lt;/label&gt;
&lt;/div&gt;
&lt;div class="form-item form-type-checkbox"&gt;
    &lt;input name="example-checkboxes[]" type="checkbox" value="ACT" class="form-checkbox"&gt; 
&lt;label class="option"&gt;ACT &lt;/label&gt;
&lt;/div&gt;
&lt;/div&gt;


I need the markup to either have labels with 'for' attributes pointing to the input elements or wrap the input elements with the label tag.

Heres thebest ive managed to come up with so far which doenst seem very satisfying

$form['tests_taken'] = array(
    '#type' =&gt; 'checkboxes',
    '#options' =&gt; drupal_map_assoc(array(t('SAT'), t('ACT'))),
    '#title' =&gt; t('What standardized tests did you take?'),
    '#attributes' =&gt; array(
      'name' =&gt; 'example-checkboxes[]'
    )
  );

  $form['tests_taken'] = form_process_checkboxes($form['tests_taken']);

  foreach (element_children($form['tests_taken']) as $key) {
       $form['tests_taken'][$key]['#id'] = drupal_html_id('edit-' . $form['tests_taken'][$key]['#attributes']['name'] . '_' . $key);

  }

  dsm($form);
  return $form;


Which now produces this markup

&lt;div class="form-checkboxes"&gt;&lt;div class="form-item form-type-checkbox"&gt;
&lt;input name="example-checkboxes[]" type="checkbox" id="edit-example-checkboxes-sat" value="SAT" class="form-checkbox"&gt; 
&lt;label class="option" for="edit-example-checkboxes-sat"&gt;SAT &lt;/label&gt;
&lt;/div&gt;
&lt;div class="form-item form-type-checkbox"&gt;
&lt;input name="example-checkboxes[]" type="checkbox" id="edit-example-checkboxes-act" value="ACT" class="form-checkbox"&gt; 
&lt;label class="option" for="edit-example-checkboxes-act"&gt;ACT &lt;/label&gt;
&lt;/div&gt;
&lt;/div&gt;


Anyone know of a cleaner way of doing this?
Try changing your code to the following, no need for the call to form_process_checkboxes.  

function my_module_block_view($delta='') {
  $block = array();
  switch ($delta) {
    case 'myform':
    $block['content'] = drupal_get_form('mymodule_form');
    break;
  }
  return $block;
}

function mymodule_form() {

  $form = array();
  $form['tests_taken'] = array(
    '#type' =&gt; 'checkboxes',
    '#options' =&gt; drupal_map_assoc(array(t('SAT'), t('ACT'))),
    '#title' =&gt; t('What standardized tests did you take?'),
    '#attributes' =&gt; array(
      'name' =&gt; 'example-checkboxes[]'
    )
  );

  dsm($form);

  return $form;


}