0

I have created a module magento admin... But i found a problem..

My magento print the text, but don't fill in value, and when im post it, the multiselect return a empty array.

The multiselect:

The multiselect

The value: The value

My form:

protected function _prepareForm() {
    $form = new Varien_Data_Form();

    $this->setForm($form);

    $fieldset = $form->addFieldset('associar_form', array (
        'legend' => 'Informações do ramo'
    ));

    $fieldset->addField('name', 'text', array(
            'name' => 'name',
            'label' => 'Ramo de Atividade',
            'class' => 'required-entry',
            'required' => true,
    ));
    $fieldset->addField('id_erp', 'text', array(
        'name' => 'id_erp',
        'label' => 'ID ERP',
        'class' => 'required-entry',
        'required' => true,
    ));

    $fieldset->addField('website_id','select', array (
        'name' => 'website_id',
        'label' => 'Web Site',
        'class' => 'required-entry',
        'required' => true,
        'values' => Mage::getSingleton('core/resource_website_collection')->toOptionArray(),
    ));
    $fieldset->addField('entity_id', 'multiselect', array (
        'name' => 'entity_id[]',
        'label' => 'Entity Id',
        'title' => 'Entity Id',
        'index' => 'entityid',
        'class' => 'required-entry',
        'required' => true,
        'values' => Mage::getSingleton('integravet_ramo/resource_ramo_collection')->toOptionArray()
    ));


    if(Mage::registry('associar_data')) {
        $form->setValues(Mage::registry('associar_data')->getData());
    }

    return parent::_prepareForm();
}

}

Collection:

class Integravet_Ramo_Model_Resource_Ramo_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
public function _construct() {
    parent::_construct();
    $this->_init('integravet_ramo/ramo');
}

}

Resource/Ramo:

<?php
class Integravet_Ramo_Model_Resource_Ramo extends Mage_Core_Model_Resource_Db_Abstract {
    public function _construct() {
        $this->_init('integravet_ramo/ramos', 'entity_id');
    }
}

Model

<?php
class Integravet_Ramo_Model_Ramo extends Mage_Core_Model_Abstract {
    public function _construct()
    {
        parent::_construct();
        $this->_init('integravet_ramo/ramo');
    }
}
2
  • Please add the code of your option array Mage::getSingleton('integravet_ramo/resource_ramo_collection')->toOptionArray() – Abhishek Panchal Sep 20 '17 at 16:26
  • Hi @AbhishekPanchal, i've updated – Willian Sugiyama Sep 20 '17 at 16:30
0

i fixed it adding this method in my collection.php:

    public function toOptionArray()
{
    return $this->_toOptionArray('entity_id', 'name');
}

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.