Admin Form Fields in Magento



Hello all hope you are doing well, Today here in this post, I am going to cover the Form fields in Magento, by using these form fields we can create the forms in admin, as other CMS Magento has the different form fields available by default, you can use it just by using the syntax. All the different type of form fields available in Magento are located in folder lib/Varien/Data/Form/Element, it is very easy just follow the syntax given below:

1. Submit Button:

$fieldset->addField('submit', 'submit', array(
          'label'     => Mage::helper('core')->__('Submit'), //this is the core helper you can write your own helper name here as well
          'required'  => true,
          'value'  => 'Submit',
          'after_element_html' => '<small>Comments</small>',
          'tabindex' => 1
        ));

2. Button:

$fieldset->addField('button', 'button', array(
		'name'      => 'button',
		'label'     => Mage::helper('core')->__('Button'), //this is the core helper you can write your own helper name here as well
		'title'     => Mage::helper('core')->__('Button'), //this is the core helper you can write your own helper name here as well
		'value'     => Mage::helper('core')->__('Button'), //this is the core helper you can write your own helper name here as well
		'onclick' 	=> 'addingcoordinate();',
	));

Note : in the button if it is not showing the value of the button just change the setValues to the addValues, then it will show the value of the button.

3. Radio Button:

$fieldset->addField('radio', 'radio', array(
          'label'     => Mage::helper('core')->__('Radio Button'),//this is the core helper you can write your own helper name here as well
          'name'      => 'title',
          'onclick' => "addingcoordinate();",
          'onchange' => "",
          'value'  => '1',
          'disabled' => false,
          'readonly' => false,
          'after_element_html' => '<small>Note comment</small>',
          'tabindex' => 1
        ));

Or You can Create the multiple value radio button:

        
$fieldset->addField('radio', 'radio', array(
          'label'     => Mage::helper('core')->__('Radio Buttons'),
          'name'      => 'title',
          'onchange' => "",
          'onclick' => "",
          'value'  => '0',
          'values' => array(
                            array('value'=>'0','label'=>'Radio Button 1'),
                            array('value'=>'1','label'=>'Radio Button 2'),
                            array('value'=>'2','label'=>'Radio Button 3'),
                       ),
          'disabled' => false,
          'readonly' => false,
          'after_element_html' => '<small>Note comment</small>',
          'tabindex' => 1
        ));

4. Checkbox:

$fieldset->addField('checkbox', 'checkbox', array(
          'label'     => Mage::helper('core')->__('Checkbox'),
          'name'      => 'Checkbox',
          'checked' => false,
          'onchange' => "",
          'onclick' => "",
          'value'  => '1',
          'disabled' => false,
          'after_element_html' => '<small>Note comment</small>',
          'tabindex' => 1
        ));

Or You can Create the multiple value checkbox:

$fieldset->addField('checkbox', 'checkbox', array(
          'label'     => Mage::helper('core')->__('checkbox'),
          'name'      => 'Checkbox',
          'values' => array(
                            array('value'=>'0','label'=>'checkbox One'),
                            array('value'=>'1','label'=>'checkbox Two'),
                            array('value'=>'2','label'=>'checkbox Three'),
                       ),
          'onclick' => "",
          'onchange' => "",
          'value'  => '1',
          'disabled' => false,
          'after_element_html' => '<small>Note comment</small>',
          'tabindex' => 1
        ));

5. Text Field:

$fieldset->addField('product_name', 'text', array( //Database field name product_name
          'label'     => Mage::helper('core')->__('Product Name'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'product_name',
      ));

6. Text Area:

$fieldset->addField('textarea', 'textarea', array(
          'label'     => Mage::helper('core')->__('TextArea'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
          'disabled' => false,
          'readonly' => false,
          'after_element_html' => '<small>Note Comments</small>',
          'tabindex' => 1
        ));

7. Dropdown:

$fieldset->addField('status', 'select', array(
	  'label'     => Mage::helper('core')->__('Status'),
	  'class'     => 'required-entry',
	  'required'  => true,
	  'name'      => 'status',
		 'values'    => array(

			array(
				'value'     => 0,
				'label'     => Mage::helper('designtool')->__('Disabled'),
			),
			
			array(
				'value'     => 1,
				'label'     => Mage::helper('designtool')->__('Enabled'),
			),                
		),
		 
  ));

8. Password Field:

$fieldset->addField('password', 'password', array(
          'label'     => Mage::helper('core')->__('Password'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
          'style'   => "",
          'value'  => 'Password',
          'disabled' => false,
          'readonly' => false,
          'after_element_html' => '<small>Note Comments</small>',
          'tabindex' => 1
        ));

9. Time:

$fieldset->addField('time', 'time', array(
          'label'     => Mage::helper('core')->__('Time'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
          //'onclick' => "",
          //'onchange' => "",
          'value'  => '11,04,11',
          'disabled' => false,
          'readonly' => false,
          'after_element_html' => '<small>Note</small>',
          'tabindex' => 1
        ));

10. Multiselect:

$fieldset->addField('available_color', 'multiselect', array(
			'label'     => Mage::helper('core')->__('Available Colors'),
			'name'      => 'available_color',   
			'values'    => $colorarray,
			'after_element_html' => '<br/><b>Note: Select availability.</b>',
		));

11. Multiline:

$fieldset->addField('multiline', 'multiline', array(
          'label'     => Mage::helper('core')->__('Multi Line'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
          'value'  => 'hello !!',
          'disabled' => false,
          'readonly' => true,
			// 'onclick' => "",
			// 'onchange' => "",
			//'style'   => "border:10px",
			'tabindex' => 1,
          'after_element_html' => '<small>Note</small>',
          
        ));

12. Note:

$fieldset->addField('note', 'note', array(
          'text'     => Mage::helper('core')->__('Text Text'),
        ));

13. Link:

$fieldset->addField('link', 'link', array(
          'label'     => Mage::helper('core')->__('Link'),
          'style'   => "",
          'href' => 'https://www.expertwebadvisor.com',
          'value'  => 'Magento Tutorial',
          'after_element_html' => '<small>Note</small>'
        ));

14. Label:

$fieldset->addField('label', 'label', array(
          'value'     => Mage::helper('core')->__('Label'),
        ));

15. Image Upload:

$fieldset->addField('frontimage', 'image', array(
		  'label'     => Mage::helper('core')->__('Front Image'),
		  'required'  => false,
		  'name'      => 'frontimage',
	));

16. File Upload:

$fieldset->addField('frontfile', 'file', array(
          'label'     => Mage::helper('core')->__('Upload'),
          'name'		=> 'frontfile',
          'value'  => 'Uplaod',
          'disabled' => false,
          'readonly' => true,
          'after_element_html' => '<small>Note</small>',
          'tabindex' => 1
        ));

17. Date:

$fieldset->addField('date', 'date', array(
          'label'     => Mage::helper('core')->__('Date'),
          'after_element_html' => '<small>Note</small>',
          'tabindex' => 1,
          'image' => $this->getSkinUrl('images/grid-cal.gif'),
          'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
        ));

Hope it helps and you enjoyed reading, if you need the professional Magento Development we can help you, just Click on the Link and send me your requirements.

Please Like the Post on Facebook or Google+.