Hi,

I want save user address programmatically, i am using address field for this.

I am creating user pro-grammatically and saving address like this

$account = user_load(2);
$entity = entity_metadata_wrapper('user', $account);

//field_profile_address is the name of the address field
$entity->field_location->thoroughfare = '123 test lane';//address
$entity->field_location->premise = 'Apt. 2G';//address 2, apt #
$entity->field_location->locality = 'Brooklyn';//city
$entity->field_location->administrative_area = 'NY';//state
$entity->field_location->country = 'US';//country
$entity->field_location->postal_code = '11226';//zip
$entity->save();

This is not working, anyone did this ?

Thanks
Deepak

Comments

mobdeepak created an issue. See original summary.

bojanz’s picture

Category: Feature request » Support request
Priority: Critical » Normal

This should work fine, postal_code is not different from the other fields.

What do you get when you dsm() the saved address?

1kenthomas’s picture

Version: 7.x-1.1 » 7.x-1.2

Array ( ) [field_address] => Array ( [und] => Array ( [0] => Array ( [country] => US [administrative_area] => MD [sub_administrative_area] => [locality] => Testville [dependent_locality] => [postal_code] => 01267 [thoroughfare] => 1 Main St [premise] => Apartment X [sub_premise] => [organisation_name] => [name_line] => [first_name] => [last_name] => [data] => ) ) )

I am using user_save() but seem to have no issue.