how to do form #options and 'selected'?

ubuntu - April 8, 2008 - 18:58

I want to have something like

blue team
green team
purple team

The following code won't cut it. I don't know how to add 'SELECTED' in an option?

<?php
  $form
['teams'] = array(
   
'#type' => 'select',
   
'#title' => t('teams'),
   
'#multiple' => true,
   
'#options' => array('b'=>'blue team', 'g'=>'green team', 'p'=>'purple team'),
  );
?>

It didn't take my html. Let

ubuntu - April 8, 2008 - 19:02

It didn't take my html. Let me put in php wrapper

I wan to add 'selected' for multiple options.

<?php
/*
<SELECT NAME="teams" MULTIPLE SIZE=6>
<OPTION VALUE="b"          >blue team
<OPTION VALUE="g" SELECTED >green team
<OPTION VALUE="p" SELECTED >purple team
</SELECT>
*/
I don't see a way to add in 'selected' to the options.

  $form['
teams'] = array(
    '
#type' => 'select',
   
'#title' => t('teams'),
   
'#multiple' => true,
   
'#options' => array('b'=>'blue team', 'g'=>'green team', 'p'=>'purple team'),
  );
?>

any help is appreciated!

Use #default_value

nevets - April 8, 2008 - 19:06

Use #default_value

thanks for your response.

ubuntu - April 8, 2008 - 19:11

thanks for your response. can you elaborate?

How to add default value to multiple options? I need more than one values be selected. Can you add a little snippet? Thanks again.

I got it to work. Thanks for

ubuntu - April 8, 2008 - 19:16

I got it to work. Thanks for the help.

I added an array in default_value.

pls share

najibx - July 18, 2008 - 02:51

Hi,

Can you share your finding and how i go about if I wanted to put 'selected' on currently selected on this jump menu.

http://drupal.org/node/91924

 
 

Drupal is a registered trademark of Dries Buytaert.