0

I'm trying to set a select field to one specific default value by it's key (one country, which i retrieve from another form), and then disable the field.

I implement hook_form_alter, i get the correct field inside the $form array, but, when i want to set the select field to one value, nothing happens. I'm trying this way:

 $form['#node']->webform['component'][91]['value']['#default_value'] = $country;

But, this does not work. Any guess on how i can achieved this, and if this is possible or the right way to do it?

Thanks

1 Answer 1

0

This is the way I do it and it works:

// set default value to a D7 form field
$form['FIELD_NAME']['und'][0]['value'] = $country;

// prevent user from changing the field value
$form['FIELD_NAME']['#access'] = false;

Hope this helps.

1
  • Thank you for your time and your answer, but i managed to achieve what i wanted, simply by modifying $form_state.
    – Zglukk
    Commented Jan 10, 2017 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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