Category Archives: Adminhtml Forms

○ Define form structure, form templates, grids in Magento, and grid containers and elements:
Which block does a standard Magento form extend?
What is the default template for a Magento form?
Describe the role of a form container and its template.
Describe the concept of Form elements, and list system elements implemented in Magento.
Describe the concept of fieldsets.
How can you render an element with a custom template?
These code references can be used as an entry point to find answers to the questions above:
■ lib/Varien/Data/Form/*
■ Mage_Adminhtml_Block_Widget_Form
■ Mage_Adminhtml_Block_Widget_Form_Container

Adding Checkboxes To An Admin Form

If the requirement is to offer an administrator an assortment of form options from an array it is possible to use a checkbox field.

The following will simply output the data from the array as defined in the

class {Namespace}_{Module}_Block_Adminhtml_{Controller}_Edit_Tab_{Formname} extends Mage_Adminhtml_Block_Widget_Form
    protected function _prepareForm()
        $form = new Varien_Data_Form();

        $fieldset = $form->addFieldset('{formname}_form',
            array('legend' => 'Legend'));

        $possibleOptionsArray = Mage::getModel('{namespace}/{module}')->getArrayFunction('array', 'name');

        $fieldset->addField('{id}', 'checkboxes', array(
            'label'     => $this->__('Label'),
            'name'      => '{row_name}[]',
            'value'     => $currentValueArray,
            'values'    => $possibleOptionsArray,
            'disabled'  => false

Important note: ‘name’ => ‘{row_name}[]’,
The name definition should be an array that ends with [].

controller saveAction to contain the following:

foreach ($data as $key => $value)
    if (is_array($value))
        $data[$key] = implode(',',$this->getRequest()->getParam($key));