I have a custom form in a custom module with multiple select:

$form['sponsors'] = array(
 '#type' => 'select',
 '#options' => $sponsors,
 '#multiple' => TRUE,
 '#size' => 20,

But I'm stumped how to access the submitted multiple values in the form_submit function. I tried to get the values by looping through the key (one guess was $form['values']['sponsors'][$key]) but no luck... anyone can point me in right direction would be appreciated!

  • 1
    # missed in 'size' => 20,
    – monymirza
    Mar 29, 2013 at 10:08

2 Answers 2


Submitted data goes into $form_state['values'] (not $form['values']), and in the case of a multiple select/checkbox element you can filter out the selected items like this:

function MYMODULE_form_submit($form, &$form_state) {
  $selected = array_filter($form_state['values']['sponsors']);

As monymirza mentioned you're also missing the # symbol at the start of both the size and multiple keys. I imagine that error is just in your question, not in your actual code, or you'd expect to see more errors.

  • Works like a charm, thanks Clive! And yes my error on #, edited my OP Mar 29, 2013 at 10:30

in case whether the user may select more than one item, size value be written like this way:

'#size' => $multiple ? min(12, count($options)) : 0,

this is how used in (taxonomy.module).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.