Add div to checkboxes only I would like to add a &lt;div&gt; containing only checkboxes. The output I want is similar to the following.

&lt;div class="a"&gt;
  &lt;label for="check1"&gt;1&lt;/label&gt;&lt;input type="checbox" id="check1" name="check1"&gt;
  &lt;label for="check1"&gt;1&lt;/label&gt;&lt;input type="checbox" id="check2" name="check2"&gt;
  &lt;label for="check1"&gt;1&lt;/label&gt;&lt;input type="checbox" id="check3" name="check3"&gt;
&lt;/div&gt;
&lt;div class="text"&gt;&lt;input type="text" id="text" name="text"&gt;&lt;/div&gt;
&lt;div class="submit"&gt;&lt;input type="submit" value="submit"&gt;&lt;/div&gt;


In template.php I have THEME_form_alter() with the following code.

  $form['basic'] = array(
    '#prefix'=&gt; '&lt;div class="a"&gt;&lt;ul&gt;',
    '#suffix'=&gt; '&lt;/ul&gt;&lt;/div&gt;'
  );

  $form['basic']['keys']['check1'] = array(
    '#prefix' =&gt; '&lt;li&gt;&lt;label for="check1"&gt;Check1',
    '#suffix' =&gt; '&lt;/li&gt;&lt;/label&gt;',
    '#type'=&gt;'checkbox',
    '#value' =&gt;'0',
    '#pre_render' =&gt; '',
    '#id' =&gt; 'check1',
    '#name' =&gt; 'check1'
  );

  $form['basic']['keys']['check2'] = array(
    '#prefix' =&gt; '&lt;li&gt;&lt;label for="check2"&gt;Check2',
    '#suffix' =&gt; '&lt;/li&gt;&lt;/label&gt;',
    '#type'=&gt; 'checkbox',
    '#value' =&gt;'0',
    '#pre_render' =&gt; '',
    '#id' =&gt; 'check2',
    '#name' =&gt; 'check2'
  );

  $form['basic']['keys']['check3'] = array(
    '#prefix' =&gt; '&lt;li&gt;&lt;label for="check3"&gt;Check3',
    '#suffix' =&gt; '&lt;/li&gt;&lt;/label&gt;',
    '#type'=&gt; 'checkbox',
    '#value' =&gt; '0',
    '#pre_render' =&gt; '',
    '#id' =&gt; 'check3',
    '#name' =&gt; 'check3'
  );

  $form['basic']['keys']['text'] = array(
    '#prefix' =&gt; '&lt;div class="text"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#type'=&gt; 'textfield',
  );


How should I write THEME_form_alter() to be obtain the HTML output I want?
With the form elements you are using, the output you obtain is the following one.

&lt;div class="a"&gt;
  &lt;ul&gt;
    &lt;li&gt;
      &lt;label for="check1"&gt;
        Check1
        &lt;div class="form-item form-type-checkbox form-item-check1"&gt;
          &lt;input type="checkbox" id="check1" name="check1" value="1" class="form-checkbox"&gt;
        &lt;/div&gt;
      &lt;/label&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;label for="check2"&gt;
        Check2
        &lt;div class="form-item form-type-checkbox form-item-check2"&gt;
          &lt;input type="checkbox" id="check2" name="check2" value="1" class="form-checkbox"&gt; 
        &lt;/div&gt;
      &lt;/label&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;label for="check3"&gt;
        Check3
        &lt;div class="form-item form-type-checkbox form-item-check3"&gt;
          &lt;input type="checkbox" id="check3" name="check3" value="1" class="form-checkbox"&gt; 
        &lt;/div&gt;
      &lt;/label&gt;
    &lt;/li&gt;
    &lt;div class="text"&gt;
      &lt;div class="form-item form-type-textfield form-item-text"&gt;
        &lt;input type="text" id="edit-text" name="text" value="" size="60" maxlength="128" class="form-text"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/ul&gt;
&lt;/div&gt;


&lt;div class="a"&gt; is wrapped to all the elements because it's a prefix for $form['basic'], which contains all the form elements.

I would use the following code.

  $form['basic']['keys']['check1'] = array(
    '#type'=&gt; 'checkbox',
    '#title' =&gt; 'Check1',
    '#value' =&gt; '0',
    '#pre_render' =&gt; array(),
    '#prefix'=&gt; '&lt;div class="a"&gt;&lt;ul&gt;&lt;li&gt;',
    '#suffix' =&gt; '&lt;/li&gt;',
  );

  $form['basic']['keys']['check2'] = array(
    '#type'=&gt; 'checkbox',
    '#title' =&gt; 'Check2',
    '#value' =&gt; '0',
    '#pre_render' =&gt; array(),
    '#prefix' =&gt; '&lt;li&gt;',
    '#suffix' =&gt; '&lt;/li&gt;',
  );

  $form['basic']['keys']['check3'] = array(
    '#type'=&gt; 'checkbox',
    '#title' =&gt; 'Check3',
    '#value' =&gt; '0',
    '#pre_render' =&gt; array(),
    '#prefix' =&gt; '&lt;li&gt;',
    '#suffix' =&gt; '&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;'
  );

  $form['basic']['keys']['text'] = array(
    '#prefix' =&gt; '&lt;div class="text"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#type'=&gt; 'textfield',
  );


Its output is the following one.

&lt;div class="a"&gt;
  &lt;ul&gt;
    &lt;li&gt;
      &lt;div class="form-item form-type-checkbox form-item-check1"&gt;
        &lt;input type="checkbox" id="edit-check1" name="check1" value="1" class="form-checkbox"&gt;       
        &lt;label class="option" for="edit-check1"&gt;Check1 &lt;/label&gt;
      &lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;div class="form-item form-type-checkbox form-item-check2"&gt;
        &lt;input type="checkbox" id="edit-check2" name="check2" value="1" class="form-checkbox"&gt;  
        &lt;label class="option" for="edit-check2"&gt;Check2 &lt;/label&gt;
      &lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;div class="form-item form-type-checkbox form-item-check3"&gt;
        &lt;input type="checkbox" id="edit-check3" name="check3" value="1" class="form-checkbox"&gt;  
        &lt;label class="option" for="edit-check3"&gt;Check3 &lt;/label&gt;
      &lt;/div&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
&lt;div class="text"&gt;
  &lt;div class="form-item form-type-textfield form-item-text"&gt;
    &lt;input type="text" id="edit-text" name="text" value="" size="60" maxlength="128" class="form-text"&gt;
  &lt;/div&gt;
&lt;/div&gt;