views:

58

answers:

4

Most of my websites in the past have been rather limited to the United States when it came to displaying addresses. On a project I'm working on right now, however, users can add events from all over the world. My problem is how to go about dealing with the different way in which addresses are displayed across the world. For example, City/State/Zip is just a US thing.

I was figuring I would alter the inputs displayed based on the country selected but I have no idea how I'm supposed to know the way every single country does addresses.

Ideas?

+2  A: 

First of all be careful with what you make mandatory. Don't use validations like "ZIP code must contain only numbers".

Then, you should have a minimal amount of fields - Country, City, Zip Code, and 2 lines for Address.

Check out for example this book ordering site with world-wide delivery. Put a book in your basket and head to checkout to see: https://securepayment.bookdepository.co.uk/checkout/summary

Adal
I think I will essentially be following this idea. I'll leave the input fields rather loose as you mention and then make a maps API request to grab the coordinates of whatever the address is and then store that info as well. That way I can do all of my interactions/calculations based off of the coordinates and have the textual info just for visitors to read and therefore it doesn't really matter as much how they enter it.
Andrew.S
+2  A: 

Check out this website, it has information of address format for all countries, you can use it as a reference. International Address Formats

alejandrobog
+1  A: 

The way i see it you have 2 options:

1 - find how every country displays their addresses and create a template for each

$address1='23 main st';
$city='New York';
$state='NY';
$postalcode='10000';
$country='US';

include("address_format_" . $formats[$country]  . ".php");

formats would map a country to a format, allowing for multiple countries to have the same format.

2 - display all addresses in a generic way:

<address>
<?php if($address1): ?>Address: <?php echo $address1 ?><br><?php endif; ?>
<?php if($city): ?>City: <?php echo $city ?><br><?php endif; ?>
<?php if($state): ?>State: <?php echo $state ?><br><?php endif; ?>
<?php if($postalcode): ?>Postal Code: <?php echo $postalcode ?><br><?php endif; ?>
</address>
Galen
A: 

Two solutions that I can think of are:

  1. [Complex] Change address requirements based on the country.
  2. [Simple] Just have a country dropdown and just one address field where the user can enter the address however he/she would like then you just display the contents of that field.

Unless you really need the address to be split into multiple fields, I believe that the simple method of storing the entire address in one field might be best. Of course, this means that your address table won't be normalized and you won't be able to validate the address entered by the user- though validation would be pretty complex too depending on the design of your code. But, this is a balancing act between usability, design, and complexity.

Hope this helps.

Waleed Al-Balooshi