When using an EntityReference field and in hook_form_alter() hiding that field with ['access'] than after submitting form $form_state input is empty for that field.
I have field field_to_a which is an entityrefence field on content type B that references content type A.
I am using hook_form_alter() in which i am using a line like $form['field_to_a']['#access'] = FALSE;
and also setting this field to a certain value
When I am pressing submit button (my Save button) on node add:
- When I am using
$form['field_to_a']['#access'] = FALSE;
: I am loosing $form_state['input']['field_to_a'] (does not exist) and$form['field_to_a']['und'][0]['target_id']['#default_value']
(empty) and I have PHP errors. - When I am using NOT
$form['field_to_a']['#access'] = FALSE;
: I have $form_state['input']['field_to_a'] properly and node is saved without any errors.
When I am using any other field I can use ['#access'] = FALSE and not loosing input in $form_state for that field.
Is there any solution or workaround for this thing? Is it a bug or normal behavior?
Thanks