A simple plugin that will generate an HTML
select element containing all world countries. Also has a validator that will validate the input.
Just install the plugin and add the "Country select form field" component to any of your pages where you want the
select element to be rendered. You can configure the element's
required attributes, as well as the default value (either hard-coded or taken from the user's session).
Important note: To have the component auto-detect the user's languages, you need to install the Rainlab.Translate plugin.
The country can be validated using a validation rule, which validates the country based on the 2-character country code:
$data = Input::all(); $rules = [ // ... other validation rules 'country' => 'country', ]; $validation = Validator::make($data, $rules);
Getting localized country name
You can get the full country name from the submitted form in your component like this:
use the required classes:
use Input; use Multiwebinc\CountrySelect\Models\CountryList;
Then to get the English country name, you would do:
$country = CountryList::getCountryNameFromCountryCode(Input::get('country')); // e.g. Dominican Republic
Or if you want the country name in a language other than English, use the two-digit language code (see Internationalization section for a list of language codes):
$country = CountryList::getCountryNameFromCountryCode(Input::get('country'), 'es'); // e.g. República Dominicana
Countries are currently translated into the following languages:
ar - Arabic cn - Chinese cs - Czech da - Danish de - German el - Greek en - English (default) es - Spanish et - Estonian fr - French hu - Hungarian it - Italian ja - Japanese lt - Lithuanian nl - Dutch no - Norwegian pl - Polish pt - Portuguese ro - Romanian ru - Russian sk - Slovak th - Thai uk - Ukranian
This plugin has not been reviewed yet.
First version of countryselect
Mar 18, 2020