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.
过去,我的大多数网站在显示地址的时候都被限制在美国。在我现在正在做的一个项目中,用户可以添加来自世界各地的事件。我的问题是如何处理地址在世界各地显示的不同方式。例如,City/State/Zip就是美国的东西。
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?
想法吗?
4 个解决方案
#1
2
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.
然后,您应该有最少的字段——国家、城市、邮政编码和2行地址。
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
以这本书订购网站为例,你可以在全球范围内订购。把一本书放在你的篮子里,然后去结帐:https://securepayment.bookdepository.co.uk/checkout/summary
#2
2
Check out this website, it has information of address format for all countries, you can use it as a reference. International Address Formats
看看这个网站,它有所有国家的地址格式信息,你可以用它作为参考。国际地址格式
#3
1
The way i see it you have 2 options:
在我看来,你有两个选择:
1 - find how every country displays their addresses and create a template for each
1 -找出每个国家如何显示它们的地址,并为每个国家创建一个模板
$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:
2 -以通用方式显示所有地址:
<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>
#4
0
Two solutions that I can think of are:
我能想到的两个解决方案是:
- [Complex] Change address requirements based on the country.
- 【复杂】根据国家改变地址要求。
- [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.
- [Simple]只有一个国家的下拉菜单,只有一个地址字段,用户可以在其中输入地址,但他/她希望你只显示该字段的内容。
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.
希望这个有帮助。
#1
2
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.
然后,您应该有最少的字段——国家、城市、邮政编码和2行地址。
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
以这本书订购网站为例,你可以在全球范围内订购。把一本书放在你的篮子里,然后去结帐:https://securepayment.bookdepository.co.uk/checkout/summary
#2
2
Check out this website, it has information of address format for all countries, you can use it as a reference. International Address Formats
看看这个网站,它有所有国家的地址格式信息,你可以用它作为参考。国际地址格式
#3
1
The way i see it you have 2 options:
在我看来,你有两个选择:
1 - find how every country displays their addresses and create a template for each
1 -找出每个国家如何显示它们的地址,并为每个国家创建一个模板
$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:
2 -以通用方式显示所有地址:
<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>
#4
0
Two solutions that I can think of are:
我能想到的两个解决方案是:
- [Complex] Change address requirements based on the country.
- 【复杂】根据国家改变地址要求。
- [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.
- [Simple]只有一个国家的下拉菜单,只有一个地址字段,用户可以在其中输入地址,但他/她希望你只显示该字段的内容。
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.
希望这个有帮助。