We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Countries Select

Development and Programming

BridgingUnit's avatar
BridgingUnit
214 posts
16 years ago
BridgingUnit's avatar BridgingUnit

The BU_countries_select plugin provides an easy means of adding a Country Select drop down box to the front-end of your site. This is a very simple plugin whose primary purpose is to just save you from a bit of typing.

It is a single tag variable, but there are a range of optional parameters that are available to allow you to control things. There are parameters for ‘name’, ‘class’, ‘id’, ‘style’ which map to attributes for the select element produced, and ‘selected’, which maps to an attribute for a chosen option element should you wish to highlight it.

Examples:

{exp:bu_countries_select}

{exp:bu_countries_select name='your-country'}

{exp:bu_countries_select name='your-country' id='select-country'}

{exp:bu_countries_select name='your-country' id='select-country' selected='United Kingdom'}

If you need to adjust the country list, just open the plugin file and adjust the $countries array.

Latest version available for download from the BU Countries Select page on my website.

I wrote this last night as I’m currently working on a project that required a dropdown like this in a member registration form. Initially I just wrote up plain code for it, but when I needed to repeat it for the edit profile page too and faced having to add conditional checks for 200+ options I thought it was time to get my hands dirty and put this together.

I should add that I was inspired to roll my sleeves up on this when I remembered that something similar had been done before by Nathan Pitman - his UK Counties Select plugin

I hope someone else finds it useful too.

       
Nathan Pitman's avatar
Nathan Pitman
531 posts
16 years ago
Nathan Pitman's avatar Nathan Pitman

Nice work. 😊

       
BridgingUnit's avatar
BridgingUnit
214 posts
16 years ago
BridgingUnit's avatar BridgingUnit

Thanks Nathan 😊 Hope we can find a way of combining things.

       
Shannon Smith's avatar
Shannon Smith
161 posts
16 years ago
Shannon Smith's avatar Shannon Smith

I’d like to try this plugin, but I’m having trouble accessing your site. It’s timing out right now. I can get to the homepage, but not to the plugin page.

       
Shannon Smith's avatar
Shannon Smith
161 posts
16 years ago
Shannon Smith's avatar Shannon Smith

Never mind… seems to have come back up. Downloading it now.

       
BridgingUnit's avatar
BridgingUnit
214 posts
16 years ago
BridgingUnit's avatar BridgingUnit

Sorry Shannon - been having server trouble today. My backroom boys are on the case and busy getting things ship-shape again though. Glad you managed to get access at last and hope it does what you need.

       
Shannon Smith's avatar
Shannon Smith
161 posts
16 years ago
Shannon Smith's avatar Shannon Smith

Works like a charm! Thanks!

Now, what would be really fantatastic is to have a provinces/state drop-down auto populate based on country selected. And, if there are no provinces/states for a particular country, then just have a textbox for the user to enter one… and if it was easy to enter in provinces and states for countries, then that would be absolutely perfect, as it could be then customized to each person’s needs.

Hey… I can dream, right?

       
BridgingUnit's avatar
BridgingUnit
214 posts
16 years ago
BridgingUnit's avatar BridgingUnit

No worries.

Wow, that would be a lot of states….

We are hoping to make something that makes it a little easier for people to customise to need. But, until then, if you’re after US states or UK counties then Nathan Pitman’s got them covered for you.

       
Shannon Smith's avatar
Shannon Smith
161 posts
16 years ago
Shannon Smith's avatar Shannon Smith

Yeah… that would be a lot of states if you tried to do the whole world, but what would be neat would be to do say Canada and the US for example and still have all the countries available. If the country selected isn’t Canada or the US, then allow them to type in the city or state in a textbox. Something like that would be ideal. If you make which states are included with which countries customizable, then the plugin could work for everyone. However, something like this, it might be best to pull the state info from the database. Anyway, just some thoughts I had. There are a lot of these available through jquery, php, etc. I haven’t been able to find one that I can implement like this… I just looked today though, so there may be something.

By the way, you have a documentation error with the plugin. The parameter name your plugin requires is “selected”, not “select”. It wasn’t working for me, so I guessed that you meant it to be “selected”, and it works now. I wanted to mention it in case anyone else gets stuck.

Thanks for this!

       
Shannon Smith's avatar
Shannon Smith
161 posts
16 years ago
Shannon Smith's avatar Shannon Smith

I also had a validation error with this because some countries have a ’ in their name.

So, open up the php file and change these:

"S'Lovak Republic"

to

"S’Lovak Republic"

and

"Cote D'Ivoire (Ivory Coast)"

to

"Cote D’Ivoire (Ivory Coast)"

No big deal really, but I like things to validate.

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
16 years ago
Ingmar Greil's avatar Ingmar Greil

S’Lovak Republic? “Slovenská republika” if you insist, otherwise Slovak Republic, no apostrophe.

       
Shannon Smith's avatar
Shannon Smith
161 posts
16 years ago
Shannon Smith's avatar Shannon Smith

Yeah… I thought that country name was a bit odd but I thought it might have been the way that Europe prefers it. Good to know… because I really had not heard of it with an apostrophe like that before!

       
BridgingUnit's avatar
BridgingUnit
214 posts
16 years ago
BridgingUnit's avatar BridgingUnit

Thanks for pointing these out Shannon and Ingmar. Well spotted. I’ve amended documentation and will amend download.

       
Derek Hogue's avatar
Derek Hogue
316 posts
16 years ago
Derek Hogue's avatar Derek Hogue

Of interest to folks in this thread, I just posted my REEgion Select plugin, which expands on the aforementioned plugins and addresses some of the ideas above. 😊

       
BridgingUnit's avatar
BridgingUnit
214 posts
16 years ago
BridgingUnit's avatar BridgingUnit

Thanks D-Rock. For people looking for other related things, there are also Sue Crocker’s FieldFrame countries select field type, and HCC Development’s country/state AJAX selector.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.