checkboxes on submit not showing correct values. Shows 0 always I am working with a form which contains list of checkboxes based on country. checkboxes are rendered correctly. But on submit, I don't get checkboxes' correct values. It always gets submitted as NOT CHECKED. My code is as below:

    foreach($fields as $id=&gt;$title) {
          $form['test'.$code]['fields-'.$code] = array(
              '#type' =&gt; 'checkboxes',
              '#options' =&gt; drupal_map_assoc(array_keys($fields)),
              '#title' =&gt; t('Title'),
              '#attributes' =&gt; array('name' =&gt; 'field-'.$code.'-'.$id),
          );
        }

    function config_submit($form, &amp;$form_state) {
      var_dump($form_state['values']);
      exit;
    }


outputs :

array (size=13)
  'fields-dk' =&gt; 
    array (size=7)
      'title' =&gt; int 0
      'reason' =&gt; int 0
      'doc-reference' =&gt; int 0
      'description' =&gt; int 0
      'upload-claim-file' =&gt; int 0
      'product-detail' =&gt; int 0
      'barcode-num' =&gt; int 0


Why is it returning always as 0? What am I missing?
While we can't see how your form is built completely, it might be that your custom attributes are affecting the element "name" in the form state.

i.e change

'#attributes' =&gt; array('name' =&gt; 'field-'.$code.'-'.$id),


to 

'#attributes' =&gt; array('data-name' =&gt; 'field-'.$code.'-'.$id),