dropdown-attribute – Magento: Add Dropdown Value from Another Database to Text Field

dropdown-attribute

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

Best Answer

$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()

Related Topic