B-219 Sec-55 Noida, India
+918010221733

Magento admin form fields

In this tutorial, i will show you all different magento admin form fields we can use in admin forms.

Magento has many different type of field available by default, so lets take a look the syntax of using each of these fields.

if you wan to to validate fields check my magento validation post.

You can add form fileds in form.php in class like YOURPACKAGE_YOURMODULE_Block_Adminhtml_Form_Edit_Tab_Form inside the _prepareForm() function. All the different type of form fields available in magento are located in folder libVarienDataFormElement
Text
01    $fieldset->addField(‘title’, ‘text’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘This is Text Field’),
03              ‘class’     => ‘required-entry’,
04              ‘required’  => true,
05              ‘name’      => ‘title’,
06              ‘onclick’ => “alert(‘on click’);”,
07              ‘onchange’ => “alert(‘on change’);”,
08              ‘style’   => “border:10px”,
09              ‘value’  => ‘hello !!’,
10              ‘disabled’ => false,
11              ‘readonly’ => true,
12              ‘after_element_html’ => ‘<small>Comments</small>’,
13              ‘tabindex’ => 1
14            ));

Time
01    $fieldset->addField(‘time’, ‘time’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘This is Time Field’),
03              ‘class’     => ‘required-entry’,
04              ‘required’  => true,
05              ‘name’      => ‘title’,
06              ‘onclick’ => “”,
07              ‘onchange’ => “”,
08              ‘value’  => ‘12,04,15’,
09              ‘disabled’ => false,
10              ‘readonly’ => false,
11              ‘after_element_html’ => ‘<small>Comments</small>’,
12              ‘tabindex’ => 1
13            ));

Textarea
01    $fieldset->addField(‘textarea’, ‘textarea’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘This is TextArea Field’),
03              ‘class’     => ‘required-entry’,
04              ‘required’  => true,
05              ‘name’      => ‘title’,
06              ‘onclick’ => “”,
07              ‘onchange’ => “”,
08              ‘value’  => ‘<b><b/>’,
09              ‘disabled’ => false,
10              ‘readonly’ => false,
11              ‘after_element_html’ => ‘<small>Comments</small>’,
12              ‘tabindex’ => 1
13            ));

Submit Button
1    $fieldset->addField(‘submit’, ‘submit’, array(
2              ‘label’     => Mage::helper(‘core’)->__(‘Submit button’),
3              ‘required’  => true,
4              ‘value’  => ‘Submit’,
5              ‘after_element_html’ => ‘<small>Comments</small>’,
6              ‘tabindex’ => 1
7            ));

Dropdown / Selectbox
01    $fieldset->addField(‘select’, ‘select’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Select’),
03              ‘class’     => ‘required-entry’,
04              ‘required’  => true,
05              ‘name’      => ‘title’,
06              ‘onclick’ => “”,
07              ‘onchange’ => “”,
08              ‘value’  => ‘1’,
09              ‘values’ => array(‘-1’=>’Please Select..’,’1′ => ‘Option1′,’2’ => ‘Option2’, ‘3’ => ‘Option3’),
10              ‘disabled’ => false,
11              ‘readonly’ => false,
12              ‘after_element_html’ => ‘<small>Comments</small>’,
13              ‘tabindex’ => 1
14            ));

here is another way to add Dropdown or select box
01    $fieldset->addField(‘select2’, ‘select’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Select Type2’),
03              ‘class’     => ‘required-entry’,
04              ‘required’  => true,
05              ‘name’      => ‘title’,
06              ‘onclick’ => “”,
07              ‘onchange’ => “”,
08              ‘value’  => ‘4’,
09              ‘values’ => array(
10                                    ‘-1’=>’Please Select..’,
11                                    ‘1’ => array(
12                                                    ‘value’=> array(array(‘value’=>’2’ , ‘label’ => ‘Option2’) , array(‘value’=>’3’ , ‘label’ =>’Option3′) ),
13                                                    ‘label’ => ‘Size’  
14                                               ),
15                                    ‘2’ => array(
16                                                    ‘value’=> array(array(‘value’=>’4’ , ‘label’ => ‘Option4’) , array(‘value’=>’5’ , ‘label’ =>’Option5′) ),
17                                                    ‘label’ => ‘Color’ 
18                                               ),                                       
19   
20                               ),
21              ‘disabled’ => false,
22              ‘readonly’ => false,
23              ‘after_element_html’ => ‘<small>Comments</small>’,
24              ‘tabindex’ => 1
25            ));

Radio Button
01    $fieldset->addField(‘radio’, ‘radio’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Radio’),
03              ‘name’      => ‘title’,
04              ‘onclick’ => “”,
05              ‘onchange’ => “”,
06              ‘value’  => ‘1’,
07              ‘disabled’ => false,
08              ‘readonly’ => false,
09              ‘after_element_html’ => ‘<small>Comments</small>’,
10              ‘tabindex’ => 1
11            ));

here is another way to add  radio button
01    $fieldset->addField(‘radio2’, ‘radios’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Radios’),
03              ‘name’      => ‘title’,
04              ‘onclick’ => “”,
05              ‘onchange’ => “”,
06              ‘value’  => ‘2’,
07              ‘values’ => array(
08                                array(‘value’=>’1′,’label’=>’Radio1’),
09                                array(‘value’=>’2′,’label’=>’Radio2’),
10                                array(‘value’=>’3′,’label’=>’Radio3’),
11                           ),
12              ‘disabled’ => false,
13              ‘readonly’ => false,
14              ‘after_element_html’ => ‘<small>Comments</small>’,
15              ‘tabindex’ => 1
16            ));

Password Field
01    $fieldset->addField(‘password’, ‘password’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Password’),
03              ‘class’     => ‘required-entry’,
04              ‘required’  => true,
05              ‘name’      => ‘title’,
06              ‘onclick’ => “”,
07              ‘onchange’ => “”,
08              ‘style’   => “”,
09              ‘value’  => ‘hello !!’,
10              ‘disabled’ => false,
11              ‘readonly’ => false,
12              ‘after_element_html’ => ‘<small>Comments</small>’,
13              ‘tabindex’ => 1
14            ));

another way to add password field
01    $fieldset->addField(‘obscure’, ‘obscure’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Obscure’),
03              ‘class’     => ‘required-entry’,
04              ‘required’  => true,
05              ‘name’      => ‘obscure’,
06              ‘onclick’ => “”,
07              ‘onchange’ => “”,
08              ‘style’   => “”,
09              ‘value’  => ‘123456789’,
10              ‘after_element_html’ => ‘<small>Comments</small>’,
11              ‘tabindex’ => 1
12            ));

Note
1    $fieldset->addField(‘note’, ‘note’, array(
2              ‘text’     => Mage::helper(‘core’)->__(‘Text Text’),
3            ));

Multiselect
01    $fieldset->addField(‘multiselect2’, ‘multiselect’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Select Type2’),
03              ‘class’     => ‘required-entry’,
04              ‘required’  => true,
05              ‘name’      => ‘title’,
06              ‘onclick’ => “return false;”,
07              ‘onchange’ => “return false;”,
08              ‘value’  => ‘4’,
09              ‘values’ => array(
10                                    ‘-1’=> array( ‘label’ => ‘Please Select..’, ‘value’ => ‘-1’),
11                                    ‘1’ => array(
12                                                    ‘value’=> array(array(‘value’=>’2’ , ‘label’ => ‘Option2’) , array(‘value’=>’3’ , ‘label’ =>’Option3′) ),
13                                                    ‘label’ => ‘Size’  
14                                               ),
15                                    ‘2’ => array(
16                                                    ‘value’=> array(array(‘value’=>’4’ , ‘label’ => ‘Option4’) , array(‘value’=>’5’ , ‘label’ =>’Option5′) ),
17                                                    ‘label’ => ‘Color’ 
18                                               ),                                       
19   
20                               ),
21              ‘disabled’ => false,
22              ‘readonly’ => false,
23              ‘after_element_html’ => ‘<small>Comments</small>’,
24              ‘tabindex’ => 1
25            ));

Multiline
01    $fieldset->addField(‘multiline’, ‘multiline’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Multi Line’),
03              ‘class’     => ‘required-entry’,
04              ‘required’  => true,
05              ‘name’      => ‘title’,
06              ‘onclick’ => “”,
07              ‘onchange’ => “”,
08              ‘style’   => “border:10px”,
09              ‘value’  => ‘hello !!’,
10              ‘disabled’ => false,
11              ‘readonly’ => true,
12              ‘after_element_html’ => ‘<small>Comments</small>’,
13              ‘tabindex’ => 1
14            ));

Link
1    $fieldset->addField(‘link’, ‘link’, array(
2              ‘label’     => Mage::helper(‘fore’)->__(‘Link’),
3              ‘style’   => “”,
4              ‘href’ => ‘raisereview.com’,
5              ‘value’  => ‘RaiseReview by R Vadgama’,
6              ‘after_element_html’ => ”
7            ));

Label
1    $fieldset->addField(‘label’, ‘label’, array(
2              ‘value’     => Mage::helper(‘core’)->__(‘Label Text’),
3            ));

Image Upload
1    $fieldset->addField(‘image’, ‘image’, array(
2              ‘value’     => ‘http://raisereview.com/logo.png’,
3            ));

File Upload
1    $fieldset->addField(‘file’, ‘file’, array(
2              ‘label’     => Mage::helper(‘core’)->__(‘Upload’),
3              ‘value’  => ‘Uplaod’,
4              ‘disabled’ => false,
5              ‘readonly’ => true,
6              ‘after_element_html’ => ‘<small>Comments</small>’,
7              ‘tabindex’ => 1
8            ));

Date
1    $fieldset->addField(‘date’, ‘date’, array(
2              ‘label’     => Mage::helper(‘core’)->__(‘Date’),
3              ‘after_element_html’ => ‘<small>Comments</small>’,
4              ‘tabindex’ => 1,
5              ‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
6              ‘format’ => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
7            ));

Checkbox
01    $fieldset->addField(‘checkbox’, ‘checkbox’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Checkbox’),
03              ‘name’      => ‘Checkbox’,
04              ‘checked’ => false,
05              ‘onclick’ => “”,
06              ‘onchange’ => “”,
07              ‘value’  => ‘1’,
08              ‘disabled’ => false,
09              ‘after_element_html’ => ‘<small>Comments</small>’,
10              ‘tabindex’ => 1
11            ));

another way to add checkbox
01    $fieldset->addField(‘checkboxes’, ‘checkboxes’, array(
02              ‘label’     => Mage::helper(‘core’)->__(‘Checkboxs’),
03              ‘name’      => ‘Checkbox’,
04              ‘values’ => array(
05                                array(‘value’=>’1′,’label’=>’Checkbox1’),
06                                array(‘value’=>’2′,’label’=>’Checkbox2’),
07                                array(‘value’=>’3′,’label’=>’Checkbox3’),
08                           ),
09              ‘onclick’ => “”,
10              ‘onchange’ => “”,
11              ‘value’  => ‘1’,
12              ‘disabled’ => false,
13              ‘after_element_html’ => ‘<small>Comments</small>’,
14              ‘tabindex’ => 1
15            ));

(Visited 817 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.