How to set checkbox if validation fails? I am creating a form which has checkbox, and options for checkbox are coming dynamically. In submit function I am rebuilding form if validation fails. all values are rendering but previously checked checkbox is not checking.

below is the code:

function modulename_form(){
      $header = array();
      $rows = array();
      $conditions = '';
      $orderby = array( 'pass_lname' =&gt; 'ASC'); 
      $unmapped_data = capcup_get_unmapped_passengers_data($conditions , $orderby);

      foreach ($unmapped_data as $key =&gt; $value) {
        $user = user_load($value-&gt;pass_uid);
        $insertion = !empty($value-&gt;pass_insertion)? $value-&gt;pass_insertion . ' ': '';
        if (empty($buttons)) {
          $row['name'] = '&lt;a href="mailto:'  . $user-&gt;mail . '"&gt;' . check_plain($value-&gt;pass_lname . ' ' . $insertion . $value-&gt;pass_fname) . '&lt;/a&gt;';
        }
        else {
          $row['name'] = '&lt;a target="_blank" href="/passagier/'  . $value-&gt;passenger_uid . '"&gt;' . check_plain($value-&gt;passenger_lname . ' ' . $insertion . $value-&gt;passenger_fname) . '&lt;/a&gt;';
        }
        $row['phone'] = $value-&gt;pass_tel;
        $row['practicecode'] = $value-&gt;pass_practcode;    
          $form['active'] =  array(
          '#type' =&gt; 'checkbox',
          '#return_value' =&gt; $value-&gt;pass_uid,
          '#attributes' =&gt; array(
              'name' =&gt; array('nodes[' . $value-&gt;pass_uid . ']'),
            )
          );
          $row['active'] =  drupal_render($form['active']);
        $rows[$value-&gt;pass_uid] = $row;
      }

      $form['nodes'] = array(
        '#theme' =&gt; 'table',
        '#header' =&gt; $header,
        '#rows' =&gt; $rows,
        '#empty' =&gt; t('No passenger available.'),
      );
return $form;
}


submit function:

function modulename_submit($form, $form_state) {
  if (in_array('boat', $account-&gt;roles)) {
      $form_state['rebuild'] = TRUE;
      form_set_error('boat_user_info][emailaddress', 'Dit e-mailadres is al in gebruik.');
      return FALSE;
    }
}


I am writing form function like above because to get structure like below image:


When form will rebuilt all fields will remembered there previous value but checkbox is not remembered its value. I tried by adding default_value and all but not worked. Please suggest me how can I achieve that.
All form validations should be done in form validate function and not in submit function. Read this article

Hope it helps. :)