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

Was it helpful?

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
scroll top