How to inject postal address into user entity via custom registration form I'm using the postal address module to obtain a user's postal address when they register on the site. The registration form is created by a custom module I made.

I'm able to get the form to display the postal address fields correctly (they modify based on your country, etc.), but when I go to process the form in HOOK_submit(), I hit a problem.

The submit function adds the user entity and puts the correct information in for the user. It also creates a new line in the field_data_field_postal_address table in the db as it should. But the address fields are all empty. 

I think it is very close to working, but I suspect that something is wrong with the structure of the array I'm passing in to the 'field_postal_address' custom entity field. 

function user_registration_form_submit($form, &amp;$form_state){
drupal_set_message("User registration submitted");
dsm($form_state);

$edit = array(
    'name' =&gt; $form_state['values']['name'],
    'pass' =&gt; $form_state['values']['password'],
    'mail' =&gt; $form_state['values']['mail'],
    'init' =&gt; $form_state['values']['mail'],
    'field_postal_address' =&gt; array(LANGUAGE_NONE =&gt; array(array('value' =&gt; $form_state['values']['address']))),
    'status' =&gt; 1,
    'access' =&gt; REQUEST_TIME,
);
$newUser = user_save(drupal_anonymous_user(), $edit);
}


So, the question is, why is this function injecting an empty row of data into the field_postal_address field?
I managed to figure out the problem. Apparently you can't load the new user array with the position of the array where the address fields are located. Instead you have to load the address array into a new variable, and pass THAT into the "field_postal_address" entity field.

So, in my solution, I loaded the address array into the $ary_address array. Then I passed that into the postal address array.

$ary_address = $form_state['values']['address']['address'];

$edit = array(
    'name' =&gt; $form_state['values']['name'],
    'field_fname' =&gt; array(LANGUAGE_NONE =&gt; array(array('value' =&gt; $form_state['values']['field_fname']))),
'field_lname' =&gt; array(LANGUAGE_NONE =&gt; array(array('value' =&gt; $form_state['values']['field_lname']))),
    'pass' =&gt; $form_state['values']['password'],
    'mail' =&gt; $form_state['values']['mail'],
    'init' =&gt; $form_state['values']['mail'],
    'field_postal_address' =&gt; array(LANGUAGE_NONE =&gt; array($ary_address)),
    'status' =&gt; 1,
    'access' =&gt; REQUEST_TIME,
);
$newUser = user_save(drupal_anonymous_user(), $edit);