Custom Addresses

Last edit: Jan 18, 2019
  • Contributors:
  • diana-lakatos
  • lemingos

Custom Addresses are used to add one or more addresses to a Profile, or Customization.

Fields

Each address supports the following self-descriptive fields:

Field name Type Note
address String Address that has been sent via form – usually original input from user
latitude Float Latitude part of coordinate used for geo searching
longitude Float Longitude part of coordinate used for geo searching
formatted_address String Formatted address that you want to display on your site. E.g. you can send address to the Google API and get a more complete address to display.
apartment String Apartment number
street String
suburb String
city String
state String
country String
iso_country_code String 2 letter ISO code
postcode String

Defining

Enable CustomAddresses by adding a Property with type set to address, for example:

- name: hq_address
  type: address
- name: correspondence_address
  type: address

Form configuration

Having this declaration in any user_profile_types/ file will result in 2 CustomAddresses being available in the form configuration, where they can be used for example like this:

profiles:
  validation: { presence: true }
  seller:
    validation: { presence: true }
    custom_addresses:
      hq_address:
        validation: { presence: true }
        address:
          validation: { presence: true }
        city:
        state:
          validation: { presence: true }
        street:
        country:
        postcode:
      correspondence_address:
        address:
          validation: { presence: false }
        city:
        state:
        street:
        country:
        postcode:

Another example, adding CustomAddress for a Customization named "EmergencyContact":

customizations:
  emergency_contacts:
    custom_addresses:
      contact_address:
        city:
        street:
    properties:
      contact_name:
      contact_email:
      contact_phone:
      contact_address:

Displaying, updating

After setting up addresses as described above, you can further customize them in the markup for the forms:


<h2>Headquarters address</h2>
<label for="hq_address">Address</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.address.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.address.name }}" id="hq_address" type="text">
{% if form_builder.errors['profiles.seller.custom_addresses.hq_address.address'] %}
  <p>{{ form_builder.errors['profiles.seller.custom_addresses.hq_address.address'] }}</p>
{% endif %}

<label for="hq_city">City</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.city.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.city.name }}" id="hq_city" type="text">

<label for="hq_street">Street</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.street.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.street.name }}" id="hq_street" type="text">

<label for="hq_state">State</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.state.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.state.name }}" id="hq_state" type="text">
{% if form_builder.errors['profiles.seller.custom_addresses.hq_address.state'] %}
  <p>{{ form_builder.errors['profiles.seller.custom_addresses.hq_address.state'] }}</p>
{% endif %}

<label for="hq_country">Country</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.country.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.country.name }}" id="hq_country" type="text">

<label for="hq_postcode">Postcode</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.postcode.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.hq_address.postcode.name }}" id="hq_postcode" type="text">



<h2>Correspondence address</h2>
<label for="correspondence_address">Address</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.address.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.address.name }}" id="correspondence_address" type="text">

<label for="correspondence_city">City</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.city.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.city.name }}" id="correspondence_city" type="text">

<label for="correspondence_street">Street</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.street.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.street.name }}" id="correspondence_street" type="text">

<label for="correspondence_state">State</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.state.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.state.name }}" id="correspondence_state" type="text">

<label for="correspondence_country">Country</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.country.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.country.name }}" id="correspondence_country" type="text">

<label for="correspondence_postcode">Postcode</label>
<input value="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.postcode.value }}" name="{{ form_builder.fields.profiles.seller.custom_addresses.correspondence_address.postcode.name }}" id="correspondence_postcode" type="text">

Using GraphQL to query for CustomAddress geolocation

Use latitude and longitude fields in geolocation queries:

query geolocate_users(
  $per_page: Int
  $page: Int
  $query: String
  $geo_points: [GeoPoint]
  $geo_point_in_shape: GeoPoint
  $geo_radius: GeoRadius
  $geo_box: GeoBox
  $geo_box_top_left: GeoPoint
  $geo_box_bottom_right: GeoPoint
  $geo_box_top_right_bottom_left: GeoBoxTopRightBottomLeft
  $customizations_geo_points: [GeoPoint]
  $street: String
) {
  users: people(
    per_page: $per_page
    page: $page
    user: {
      profiles: [
        {
          profile_type: $profile_type
          addresses: [
            {
              street: $street
              geo_query: {
                polygon: { points: $geo_points }
                point_in_shape: { point: $geo_point_in_shape }
                radius: $geo_radius
                box: $geo_box
                box_top_left_bottom_right: { top_left: $geo_box_top_left, bottom_right: $geo_box_bottom_right }
                box_top_right_bottom_left: $geo_box_top_right_bottom_left
              }
            }
          ]
          customizations: [{ addresses: [{ geo_query: { polygon: { points: $customizations_geo_points } } }] }]
        }
      ]
    }
  ) {
    total_entries
    has_next_page
    has_previous_page
    size

    results {
      id
      slug
      name
      created_at

      default_profile: profile(profile_type: "default") {
        custom_addresses {
          name
          address
          street
        }
      }

      seller_profile: profile(profile_type: "seller") {
        custom_addresses {
          name
          address
          street
        }
      }

      buyer_profile: profile(profile_type: "buyer") {
        custom_addresses {
          name
          address
          street
        }
      }
    }
  }
}

In the example above, you can see how you can query CustomAddress both at the user_profile and customization levels.

If you wanted to find user profiles in the vicinity of (50, 20) geo point, you could do that using those parameters:

{
  "geo_radius": {
    "center": {
      "lat": 50,
      "lng": 20
    },
    "distance": "25km"
  }
}

Questions?

We are always happy to help with any questions you may have.