I need to create a custom module which allows admin to create Zones for different countries. I need to add 'allow country' field (just like in default magento System > Configuration > General > Countries Options) in my form where admin can select the countries for a zone.

I Just need to add a countries multi select field in my custom module admin form.

Can anyone help me how to do this. Thanks..

  • sorry forgot to ask, you wanna add this in your custom config section or admin form?
    – Shathish
    Oct 28, 2013 at 5:47
  • I need to add the field in my custom module admin form. Oct 28, 2013 at 5:50

3 Answers 3


I found the solution.
To add a country multi select dropdown in your form you need to add below code in your Block/Adminhtml/ModuleName/Edit/Tab/Form.php file.

$countryList = Mage::getModel('directory/country')->getResourceCollection()->loadByStore()->toOptionArray(true);
$fieldset->addField('countries', 'multiselect', array(
            'name'      => 'countries[]',
            'label'     => Mage::helper('zones')->__('Countries'),
            'title'     => Mage::helper('zones')->__('Countries'),
            'required'  => true,
            'values'    => $countryList,

To bring in the allowed countries field in your custom module config:

add the following to your module's system.xml

<sallowspecific translate="label">
    <label>Ship to Applicable Countries</label>
<specificcountry translate="label">
    <label>Ship to Specific Countries</label>

under <fields> tag in your custom section.

To add it in the admin form:

in app/code/local/Yourmodulename/Block/Adminhtml/Yourmodulename/Edit/Tab/Form.php

$countryList = Mage::getModel('directory/country')->getResourceCollection()->loadByStore()->toOptionArray(true);
$fieldset->addField('allowed_countries', 'multiselect', array( /* "allowed_countries" is the column name in your custom table to store these values */
    'name'      => 'countries[]',
    'label'     => Mage::helper('yourmodulename')->__('Allowed Countries'),
    'title'     => Mage::helper('yourmodulename')->__('Allowed Countries'),
    'required'  => true, /* only if it is required */
    'values'    => $countryList,


  • You have to write logic to save the multiselect values in database in saveAction()

to display this in admin grid:

refer this link.

  • To save the multiselect values you just need to implode the post data using "," (eg. $countries = implode(",",$selectedCountries)) and save it in database. Magento will do everything else to get it back on edit or view page. Oct 28, 2013 at 9:38
$fieldset->addField('country', 'select', array(  
        'name' => 'country',  
        'label' => 'Country',  
        'values' => Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(),  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.