For those who develop code, the address appears in the database as a field added with an array containing the address components. You might want these details if you are creating an import module or are diagnosing something at the database level.

If you add Address with the machine name box containing address, you end up with a Field field named field_address. The actual address is an array at field_address['und'][0].

The following dump was created by adding an address, selecting country Australia, then typing the names of each address box in the box. The result will vary by country. There are current issues to fix the address formatting and validation for several countries. Please test for your country.

["field_address"] =>  array(1) {
    ["und"] => array(1) {
      [0] => array(14) {
        ["country"] => string(2) "AU"
        ["administrative_area"] => string(5) "State"
        ["sub_administrative_area"] => NULL
        ["locality"] => string(4) "City"
        ["dependent_locality"] => NULL
        ["postal_code"] => string(11) "Postal Code"
        ["thoroughfare"] => string(9) "Address 1"
        ["premise"] => string(9) "Address 2"
        ["sub_premise"] => NULL
        ["organisation_name"] => NULL
        ["name_line"] => NULL
        ["first_name"] => NULL
        ["last_name"] => NULL
        ["data"] => NULL
      }
    }
  }

Comments

MarioBrus’s picture

The textfields have a placeholder attribute somewhere? I can't find it.

Anonymous’s picture

Please consider adding an example of how to add an addressfield to a custom form. I have tried the following in my custom module without success.

$form['address'] = array(
'#title' => t('Address'),
'#type' => 'addressfield',
'#required' => TRUE,
'#context' => array('countries' => array('US')),
'#default_value' => array('country' => 'US'),
);