0

I am using Magento1.9.2.4 I want to add 4 field one of them id selectbox. And I want to load the options for that from another custom module's table, How can I achieve this. And yes I want to save the 3 other fields value in other custom table. Please Suggest how can I do this.

1 Answer 1

2

To add dropdown field in admin and get its option from another table-

in your modules form.php add code

 $fieldset->addField('column_name', 'select', array(
            'label' => Mage::helper('module_name')->__('Custom Label'),
            'required' => true,
            'name' => 'column_name',
            'disabled' => true,
            'values' => Mage::getModel('module_name/model_name')->getOptionArray()
        ));

Now in your model file add function

public function getOptionArray() {
        $Collections = Mage::getModel('another_module_name/another_module_name')->getCollection();

   //it is the collection of your another custom module

    $options = array();
    $options[] = array('label' => 'Please Select', 'value' => '');
    foreach ($Collections as $key => $value) {

        $options[] = array(
            'label' => $value['label_you_want_to_set'],
            'value' => $value['value_you_want_to_set']
        );
    }
    return $options;
}`
2
  • Thanks. I'll try this. And Accept it as solution if it works for me.
    – Yogita
    Oct 27, 2016 at 5:50
  • My Other Module's fields whose values I want is an text field not select type.
    – Yogita
    Oct 27, 2016 at 7:14

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.