I have a form field with type select. The results values are taken from the database. If the select list is with single value I'm displaying the value title on the submit like this:
$selected_index = $form_state['values']['select_list']; //the field is select_list
$display_value = form['select_list']['#options'][$selected_index];
dpm($display_value); //it's showing the selected option value title.
When I'm using '#multiple' => TRUE
; into the form field, It's showing error: Warning: Illegal offset type in...
How can I display the titles of the multiple values?
EDIT:
This is my code:
function mymodule_page($form, &$form_state) {
global $user;
$result = db_query('SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = :uid and type = :type', array(':uid' => $user->uid, ':type' => 'outlets'));
$droplist = array();
foreach($result as $record) {
$title = $record->title;
array_push($droplist, $title);
$form['select_list'] = array(
'#type' => 'select',
'#title' => 'Select list',
'#options' => $droplist, //I'm getting this list from my database
'#multiple' => TRUE,
);
}
function mymodule_submit($form, &$form_state) {
$selected_index = $form_state['values']['select_list'];
foreach($selected_index as $key => $sindex)
dpm($sindex);
}
1
and2
!!! .