0

I have a form, like this:

        $form['my_case_type_list']=array(
            '#type'=>'select',
            '#title' => 'Issue Type',
            '#options' => $my_list,
            '#multiple' => false,
            '#attributes'=>array('size'=>1),
            '#weight'=>2,
        );

where $my_list is an array, like this:

$array[0] = 'string 1'
$array[1] = 'string 2'
$array[2] = 'string 3'

This renders a dropdown list with the array key as the option value and the array value as the option text. I want to use a multi-dimensional array to also provide each option with a data id. An array like this:

$return_array[0] = array('name' =>'string 1', 'description'=>'description for string 1');
$return_array[1] = array('name' =>'string 2', 'description'=>'description for string 2');
$return_array[2] = array('name' =>'string 3', 'description'=>'description for string 3');

and have the description field be used, in the option value, as a data attribute. So, it would be rendered like this:

<select name="my_case_type_list" size="1" class="form-select" id="edit-my-case-type-list">
    <option data-desc='description for string 1' value="0">String 1</option>
    <option data-desc='description for string 2'  value="1">String 2</option>
    <option data-desc='description for string 3'  value="2">String 3</option>
</select>

Is this even possible? Can you assign a multi-dim array to a form? When I do, it just create option groups and each dimension of the array becomes an option.

thanks jason

0

This has been asked previously for Drupal 7 and there is no great answer so it's unlikely to be possible in Drupal 6 the answer seems to be implementing a custom theme_select

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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