An ISO standard country name drop down list for HTML form
Hello Guys, recently i got a small post in my codeigniter wiki page( about a ISO standard country code. Actually, before this i'd not any idea about such type of thing. In-fact i can remember in my first "create account" form i'd manually made a list of countries by coping them from an other site. But, right now i'm smiling by remembering all those non-standard work which i'd done once upon a time.

Any way, the parent link which i has shown in top is for codeigniter. So, i think why not i modify that so that my plain PHP programmer friends can use that in their own work. So, here is the code i'm going to share.. which i've just modify a bit.

= array(
"AG"=>"Antigua and Barbuda",
"BA"=>"Bosnia and Herzegovina",
"IO"=>"British Indian Ocean",
"BF"=>"Burkina Faso",
"CV"=>"Cape Verde",
"KY"=>"Cayman Islands",
"CF"=>"Central African Republic",
"CX"=>"Christmas Island",
"CC"=>"Cocos (Keeling) Islands",
"CD"=>"Congo, Democratic Republic of the",
"CG"=>"Congo, Republic of the",
"CK"=>"Cook Islands",
"CR"=>"Costa Rica",
"CZ"=>"Czech Republic",
"DO"=>"Dominican Republic",
"TL"=>"East Timor",
"SV"=>"El Salvador",
"GQ"=>"Equatorial Guinea",
"FK"=>"Falkland Islands (Malvinas)",
"FO"=>"Faroe Islands",
"GF"=>"French Guiana",
"PF"=>"French Polynesia",
"HK"=>"Hong Kong",
"CI"=>"Ivory Coast (Côte d\'Ivoire)",
"KR"=>"Korea, South",
"MK"=>"Macedonia, Republic of",
"MH"=>"Marshall Islands",
"AN"=>"Netherlands Antilles",
"NC"=>"New Caledonia",
"NZ"=>"New Zealand",
"NF"=>"Norfolk Island",
"PS"=>"Palestinian Territory",
"PG"=>"Papua New Guinea",
"PN"=>"Pitcairn Island",
"SH"=>"Saint Helena",
"KN"=>"Saint Kitts and Nevis",
"LC"=>"Saint Lucia",
"PM"=>"Saint Pierre and Miquelon",
"VC"=>"Saint Vincent and the Grenadines",
"SM"=>"San Marino",
"ST"=>"São Tome and Principe",
"SA"=>"Saudi Arabia",
"CS"=>"Serbia and Montenegro",
"SL"=>"Sierra Leon",
"SB"=>"Solomon Islands",
"ZA"=>"South Africa",
"GS"=>"South Georgia and the South Sandwich Islands",
"LK"=>"Sri Lanka",
"SJ"=>"Svalbard and Jan Mayen",
"TT"=>"Trinidad and Tobago",
"TC"=>"Turks and Caicos Islands",
"AE"=>"United Arab Emirates",
"GB"=>"United Kingdom",
"US"=>"United States",
"UM"=>"United States Minor Outlying Islands",
"VA"=>"Vatican City",
"VG"=>"Virgin Islands, British",
"WF"=>"Wallis and Futuna",
"EH"=>"Western Sahara",

$selectName == '')
$selectName 'country';
'<select name="'.$selectName.'">'
  if (
$topCountry as $item): 
$countryList as $countryListKey => $countryListValue):
$item == $countryListKey)
'<option value="'.$countryListKey.'">'.$countryListValue.'</option>';
$countryList as $k => $v):
'<option value="'.$k.'">'.$v.'</option>';

$topCountry = array('US','CA','GB','DE','BR','IT','ES','AU','NZ','HK');
$selectName 'countryList';

It has just 2 parts.

* Country list array which hold all the countries name along with it's 2 char country codes.

* A function "dropDownCountryList()" which will do the work for you.

The "dropDownCountryList()" has only 3 parameters. These are...

[1] $selectName : It's just the name of the SELECT form. By default it's value is "country". If you'll not provide any select name this default value will get used.

[2] $countryList : This is the country array which hold all the countries name along with it's 2 char country codes.

[3] $topCountry : This is a parameter which hold some of the country code which you might want to show in the top of all country list for quick pick. This is an optional parameter. SO, if you'll not used then he default country list will appear.

Optional parameter: $selectName, $topCountry

Required parameter : $countryList

Download the original file from here :

So Guys, that's it. I hope, you'll like it & use it in your work. If this, if any body will get any problem you can post your query at here.


16th Feb 2011 at 2:47 PM   4379 Views

Oop's, No Comments has been droped for this thread yet now.
Why don't you drop one.