Using the forms.api I wonder how I can preselect an Item.

I tried it like, the following, but failed unfortunately.


$salutation =  'Mr.';

$form['contactperson']['company_salutation'] = array(
	  '#type' => 'select',
	  '#title' => t('Salutation'),
	  '#options' => array('Ms.' => t('Ms.'), 'Mr.' => t('Mr.')),
	  '#default_value' => $salutation
);

How can I manage to preselect the desired value of an select-list?

Thanks in advance :)
Soezkan

Comments

soezkan’s picture

Is there really nobody who can help me with this?

Clarkmatic’s picture

What is not working about the form? The code you posted works when I drop it into a module. The default option is "Mr.".

soezkan’s picture

Yes thank you - it works.
I was mistaken with the use of #value and #default_value, though I wrote it in this post with #default_value.

guldi’s picture

Is there also a possibility to preselect items via GET-vars?

Eg.
?node-form[taxonomy-1]=32
or something like that?

Thanks!