How to assign default values ​​for an edit form? In my form I create a field of type list (with the widget box is checked). By default, this field has no value.

In my hook_form_alter () method, I add options (via PHP) has this field.

$form['field_genric_domains']['und']['#options']= _get_domaine_options();

if($form['field_genric_domains']['und']['#default_value'] == NULL){ 
    $form['field_genric_domains']['und']['#default_value']  = array(_get_this_domain_id());
} 


Then I set a default value. I set up a test that shows whether we are editing or creating.

When creating, it works perfectly, but when editing the table (# default_value) is empty. Normally it should contain the values ​​previously inquire.

Why? Thank you for your help
You need to check that value returned by _get_this_domain_id() function is in the array key used to create #options for form element ['field_genric_domains'] .

Example :

If _get_domaine_options() function returns array as :

array(1=>'India',2=>'USA');

Then _get_this_domain_id() should return key either 1 or 2 .That will set the default value depending on the array key .