Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using a select list in my custom module. When I select some option in the list after submitting the form, I can see the $form_state['values']['select_field'] is showing an integer.

How can I make the form_state values to show the title of the list, instead of number of the selected option?

share|improve this question
up vote 3 down vote accepted

Whatever you set as the array keys for options will be the values, so if you want to see option content rather than value, you need to set it up like that:

$form['select_field'] = array(
  '#options' => array('Text' => 'Text', 'More Text' => 'More Text'),

Or, leave the numeric keys where they are, and refer back to the original options array in your submit handler:

$selected_index = $form_state['values']['select_field'];
$display_value = $form['select_field']['#options'][$selected_index];

If you go with the first option, drupal_map_assoc() will probably be useful.

share|improve this answer
+1 for drupal_map_assoc() – Wtower Feb 18 '14 at 13:38
I'm getting the result of select list from my database, so the second way did great job. Thank you very much. – user2519032 Feb 18 '14 at 13:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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