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?


1 Answer 1


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.

  • I'm getting the result of select list from my database, so the second way did great job. Thank you very much. Feb 18, 2014 at 13:53

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.