I'm trying to programmatically edit the values of a checkbox component through hook_form_alter, but even if the rendered values are correct, only the original values are submitted.
Here is my code:

function my_form_webform_client_form_30_alter (&$form, &$form_state) {
    $form = mycustom_form($form);
}

function mycustom_form($form){  
     $form['#validate'][] = 'mycustom_webform_validate_form';
     $form['#submit'][] = 'mycustom_webform_submit';
     dpm($form['submitted']['code']['#options']); // ('0'=>'a value', '1'=>'another value');
     $codes = array('foo', 'bar'); 
     foreach ($codes as $key => $value) {
        $form['submitted']['code']['#options'][$value] = $value;
     } 
     dpm($form['submitted']['code']['#options']); // ('0'=>'a value', '1'=>'another value', '2'=>'foo', '3'=>'bar' );
     return $form;
}

function mycustom_webform_validate_form($form, &$form_state) {
    dpm($form_state['values']['submitted']);
    // selecting all checkboxes I get all the four values
}

function mycustom_webform_validate_form($form, &$form_state) {
    drupal_set_message('<pre>' . print_r($form_state, true) . '</pre>');
    // only 'a value' and 'another value' are submitted
}

What am I doing wrong?

Comments

quicksketch’s picture

Status: Active » Closed (won't fix)

As mentioned in the submission guidelines, we don't provide help with custom coding:

Any issues regarding "how do I code ..." or "how do I theme ..." will not be answered. Please look elsewhere for coding resources.

Please refer to other resources such as IRC or Drupal StackExchange to ask your questions.