I have a custom community module in which I want to allow store multi-select drop-down.

I am already displaying the drop-down but when I save it's value and then, if I edit the form, I don't see the selected value highlighting though the value is stored correctly in database.

Can anybody let me know, what am I missing in the form ?


you can add this in to your Form.php

            'name'      => 'stores[]',
            'label'     => Mage::helper('banners')->__('Store View'),
            'title'     => Mage::helper('banners')->__('Store View'),
            'required'  => true,
            'values'    => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true)

and you must have function in your module with _afterLoad function

class Mage_Banners_Model_Mysql4_Banners extends Mage_Core_Model_Mysql4_Abstract
    public function _construct()
        // Note that the banners_id refers to the key field in your database table.
        $this->_init('banners/banners', 'banners_id');

 protected function _afterLoad(Mage_Core_Model_Abstract $object)

    $select = $this->_getReadAdapter()->select()
        ->where('banners_id = ?', $object->getId());

    if ($data = $this->_getReadAdapter()->fetchAll($select)) {
        $storesArray = array();
        foreach ($data as $row) {
            $storesArray[] = $row['store_id'];
        $object->setData('store_id', $storesArray);

    return parent::_afterLoad($object);


above code is just for your help you can set it as per your column name and database tables

| improve this answer | |
  • Where should I put this function? I am using "MySQL4/Collection" approach instead of "ResourceDB/Collection" approach for model-collection. – Vivek Jan 2 '15 at 12:08
  • @Vivek. Added new class you can use it like above – liyakat Jan 2 '15 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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