I'm trying to set value of select list programmatically with hook form alter

I have select list with options:

$options = array(125 => 'USA');

and setting value like this

$form['field_news_rubrique']['und']['#options'] = $options

But this don't work.

if i change options like this

$options = array(0 => 'USA');

it's working

if i have multiple value in options like this :

$options = array(124=> 'EN', 125 => 'USA');

it's working too

bumped to the homepage by Community 18 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • I'm get it working by disable taxonomy term permission module – stomerfull Jul 10 '14 at 15:18

Do you want to set the value before submission or after?

Before submission: Use $form and set the default value for the select list using the key.

After submission: Use $form_state['values']

  • I want to set value before submission , but i get it working thank's for your post – stomerfull Jul 14 '14 at 9:41

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.