Value of the input is not preserved when it is an HTML array Suppose, we have a form, containing 3 elements:


Checkbox with special name 'name[attached]', indicating that it is a part of an array of checkboxes.
Text input
Submit button


Code

function bundles_test_form($form, &amp;$form_state)
{
    $form['name[attached]'] = array(
        '#type' =&gt; 'checkbox',
        '#required' =&gt; false,
        '#attributes' =&gt; array('name' =&gt; 'name[attached]'),
        );

    $form['date'] = array(
        '#type' =&gt; 'textfield',
        '#required' =&gt; false,
        );

    $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Submit'),
        );

    return $form;
}

function bundles_test_form_validate($form, &amp;$form_state)
{
    if (isset($form_state['input']['name']['attached']))
    {
        if ($form_state['input']['date'] === '')
        {
            form_set_error("date", 'date is required');
        }
    }
}


Question

When the form throws an error, the checkbox must be checked, but it is not. When I change the name to "name" or anything that it not the array, it works correctly. So the error is caused by the non-standard name of the input.
IMO this should work

    function mm_definition_of_the_form($form, &amp;$form_state) {
      //other code
      $form_state['rebuild'] = TRUE;

      if (isset($form_state['check_field'])) {
        //set default value of the field
      }
    }

    function mm_definition_of_the_form_validate(&amp;$form, &amp;$form_state) {
      //if is error
      $form_state['check_field'] = TRUE;
    }