How to specify entity reference fields when programmatically submitting to user_register_form You'd think this would be easy. I'm calling drupal_form_submit('user_register_form', $form_state) 
to automatically register users after they have completed filling out a Webform. 

But I have some Entity Reference fields in my user profile and form_validate is not happy with what I am submitting for them. All of the ER fields are references to taxonomy terms. Some of them are single-value fields, some of them are unlimited value fields. They have various widgets attached such as Select List, Autocomplete, Checkboxes and Radio Buttons. Some of them are Required fields, others are not. 

I've tried setting all of the following in $form_state['values'] before submitting the form:

$form_state['values']['field_foo']['und'] = $tid;
$form_state['values']['field_foo']['und'][0] = $tid;
$form_state['values']['field_foo']['und'][0]['target_id'] = $tid;


But Drupal still throws out 'An illegal choice has been detected' when it comes to validate the field, or sometimes a 'Field is required' error.

What am I doing wrong and how do I go about figuring out the right way to specify each of the fields?
I think form might be expecting in proper format that is "[entity-title] [entity_id]", so field array should look like.

'field_foo' = {
    'und' = [
        0 = {
            'target_id' = 'Title of entity ($tid)'
        }
    ]
}


Just to make sure you can form alter user form, add a custom validate and do a dsm($form_state);