Setting value to checkboxes in a form I've been having troubles with form_set_value(). I've extended the Search form, everything works, but after submission, the form values for those fields added by me return to default (see the code).

What am I doing wrong?

Thank you!

&lt;?
/**
 * implementation of function hook_form_FORM_ID_alter
 */
function myModule_form_search_form_alter( &amp;$form, &amp;$form_state, $form_id ){

    $form['myM_options']['entity'] = array(
                                            '#type' =&gt; 'radios',
                                            '#title' =&gt; 'Search by',
                                            '#default_value' =&gt; 'gene',
                                            '#options' =&gt; array(
                                                                "gene" =&gt; "Genes",
                                                                "ortholog" =&gt; "Orthologs",
                                                                "microarray" =&gt; "Microarray Features"
                                                            ),

                                        );
    $form['myM_options']['plant'] = array(
                                            '#type' =&gt; 'checkboxes',
                                            '#title' =&gt; 'Choose plants',
                                            '#options' =&gt; formatPlants(),
                                            // select all checkboxes by default
                                            '#default_value' =&gt; array_keys(formatPlants()),
                                        );
    $form['#validate'][] = 'myModule_search_validate';
    $form['#submit'][] = 'myModule_search_form_alter_submit';
}
/**
 * validation functoin
 */
function myModule_search_validate( $form, &amp;$form_state ){
    // this works as expected
    form_set_value($form['basic']['processed_keys'], trim($form_state['values']['keys']), $form_state);

    // this doesn't !!!
    form_set_value($form['myM_options']['entity'], $form_state['values']['entity'], $form_state);
    form_set_value($form['myM_options']['plant'], array( 'id_1', 'id_2' ), $form_state);
}
$form: An associative array containing the structure of the form,
  which is passed by reference. Form validation handlers are able to
  alter the form structure (like #process and #after_build callbacks
  during form building) in case of a validation error. If a validation
  handler alters the form structure, it is responsible for validating
  the values of changed form elements in $form_state['values'] to
  prevent form submit handlers from receiving unvalidated values.


So your form validation function should be as the following:

/**
 * validation functoin
 */
function myModule_search_validate( &amp;$form, &amp;$form_state ) {
  // function body
}


Then in your form submit function you need to set $form_state['rebuild'] = TRUE as following:

/**
 * submit functoin
 */
function plant_Ontlogy_search_form_alter_submit( &amp;$form, &amp;$form_state ) {
  // function body

  $form_state['rebuild'] = TRUE;
}


If setting state rebuild to TRUE didn't work with you by itself, try to set default value as the following example to each additional field:

$form['myM_options']['entity'] = array(
  '#type' =&gt; 'radios',
  '#title' =&gt; 'Search by',
  '#default_value' =&gt; isset($form_state['values']['entity'])? $form_state['values']['entity'] : 'gene',
  '#default_value' =&gt; 'gene',
  '#options' =&gt; array(
    "gene" =&gt; "Genes",
    "ortholog" =&gt; "Orthologs",
    "microarray" =&gt; "Microarray Features"
  ),
);