magento text field add dropdown value from some other database
-
12-12-2019 - |
Question
i want to add dropdown to magento custom forms fields see below
$fieldset->addField('cadmin', 'text', array(
'name' => 'cadmin',
'label' => 'Corporate Admin',
'id' => 'cadmin',
'title' => 'Corporate Admin',
'required' => false,
));
i want to show dropdown with values from database , bascially i want to show all customer group in drop down here , how can i do it
Solution
$fieldset->addField('cadmin', 'select', array(
'name' => 'cadmin',
'label' => 'Corporate Admin',
'id' => 'cadmin',
'title' => 'Corporate Admin',
'required' => false,
'values' => Mage::getModel('customer/group')->getCollection()->toOptionHash()
));
If it doesn't work with Mage::getModel('customer/group')->getCollection()->toOptionHash()
try with Mage::getModel('customer/group')->getCollection()->toOptionArray()
OTHER TIPS
Change the type from 'text' to 'select', then 'values' array of the options
$fieldset->addField('cadmin', 'select', array(
'label' => Mage::helper('core')->__('Corporate Admin'),
'name' => 'cadmin',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('core')->__('Level 1'),
),
array(
'value' => 2,
'label' => Mage::helper('core')->__('Level 2'),
),
),
));
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange