Dropdown Country List with Code Igniter and Zend Framework

Note: This assumes you are using Code Igniter, have loaded the form helper, and have followed this guide to integrating Zend Framework with CodeIgniter.

This was so easy that it was scary!

public function country_list($field_name="country",$selected="US")
{
$this->load->library('zend');
$this->zend->load('Zend/Locale');
$locale = new Zend_Locale('en_US');
$countries = ($locale->getTranslationList('Territory','en',2));
asort($countries,SORT_LOCALE_STRING);

return form_dropdown($field_name,$countries,$selected);
}

This returns a nice list of countries with the 2-letter codes as the option values.

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: