How to create a multi select list in a custom module, populate values from taxonomy term and access the selected values when the form is submitted.

I have to code below for multi select list. I want to know how to access the multiple selected values from multi select list when the form is submitted.

function rice_graph_form($form, &$form_state) {
  $form['country'] = array(
  '#title' => t('Country'),
  '#type' => 'select',
  '#multiple' => true,
  //'#description' => 'Select a Country.',
  '#options' => rice_graph_get_terms('country')
  if(isset($form_state['values'])) {
    $multivalues = $form_state['values']['country'];

1 Answer 1


In your submit handler add something like this:

$selected_countries = array_filter($form_state['values']['country']);

$selected_countries will contain the array keys of all the selected items in your Country select list. You need the array_filter to get rid of unselected items, which also come through to the submit handler but with a value of 0.


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.