Magento 1.7 – How to Add ‘Allowed Countries’ Field in Custom Form

magento-1.7module

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..

Best Answer

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,
        ));
Related Topic