1

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

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

1

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'),
          ),
      ),
  ));

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.