¿Cuál es la mejor manera de tratar con entradas de direcciones que pueden ser de varios países?

StackOverflow https://stackoverflow.com/questions/2870261

Pregunta

La mayoría de mis sitios web en el pasado han sido más bien limitado a los Estados Unidos a la hora de mostrar las direcciones. En un proyecto que estoy trabajando ahora, sin embargo, los usuarios pueden añadir eventos de todo el mundo. Mi problema es cómo hacer para hacer frente a la diferente forma en que las direcciones se muestran en todo el mundo. Por ejemplo, la ciudad / estado / código postal es sólo una cosa de Estados Unidos.

Yo estaba calculando Me alterar las entradas desplegados basándose en el país seleccionado, pero no tengo ni idea de cómo se supone que debo saber el camino cada país hace direcciones.

Las ideas?

¿Fue útil?

Solución

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

Otros consejos

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

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>

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top