Fill #options of select field I have a select field for a content type which has options generated dynamically. The options are updated in hook_form_alter(). The problem is that when I try to manipulate the posted data in submit callback, the field values are empty. Below is an example to better understand the issue.

function my_form_alter(&amp;$form, &amp;$form_state) {
    $options = array('a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3);
    $form['my_field'] = array(
        '#type' =&gt; 'select',
        '#title' =&gt; t('Label'),
        '#multiple' =&gt; TRUE,
        '#options' =&gt; $options,
        '#default_value' =&gt; '',
    );
    $form['#submit'][] = 'my_submit_handler';
}

function my_submit_handler($form) {
    echo "&lt;pre&gt;";
    var_dump($form['my_field']);
    echo "&lt;/pre&gt;";
}


If I select options 2 and 3 for example; the var_dump returns empty array().
Submitted values are contained in $form_state['values']:

function my_submit_handler($form) {
  $selected_options = array_filter($form_state['values']['my_field']);
}


e.g. if you select '1' and '2' on the form, $selected_options will be array('a', 'b')