21 Jan 2014

Magento: different form fields in admin form part two

For First Part Please take look
Magento : different form fields in Admin form part one
In this article I am going to show how to add different form fields that you can use in admin forms e.g : text,button,radio..etc. app/code/local/MyNamespace/MyModule/Block/Adminhtml/Mymodule/Edit/Tab/Form.php

Password Field :
Here is how to add a password field to an admin form, with a list of all the options
$fieldset->addField('password', 'password', array(
          'label'     => Mage::helper('form')->__('Password'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
          'onclick' => "",
          'onchange' => "",
          'style'   => "",
          'value'  => 'hello !!',
          'disabled' => false,
          'readonly' => false,
          'after_element_html' => 'Comments',
          'tabindex' => 1
        ));

$fieldset->addField('obscure', 'obscure', array(
          'label'     => Mage::helper('form')->__('Obscure'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'obscure',
          'onclick' => "",
          'onchange' => "",
          'style'   => "",
          'value'  => '123456789',
          'after_element_html' => 'Comments',
          'tabindex' => 1
        ));


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

Multiselect Field :
Here is how to add a multiselect field to an admin form, with a list of all the options
$fieldset->addField('multiselect2', 'multiselect', array(
          'label'     => Mage::helper('form')->__('Select Type2'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
          'onclick' => "return false;",
          'onchange' => "return false;",
          'value'  => '4',
          'values' => array(
                                '-1'=> array( 'label' => 'Please Select..', 'value' => '-1'),
                                '1' => array(
                                                'value'=> array(array('value'=>'2' , 'label' => 'Option2') , array('value'=>'3' , 'label' =>'Option3') ),
                                                'label' => 'Size'    
                                           ),
                                '2' => array(
                                                'value'=> array(array('value'=>'4' , 'label' => 'Option4') , array('value'=>'5' , 'label' =>'Option5') ),
                                                'label' => 'Color'   
                                           ),                                         
                                  
                           ),
          'disabled' => false,
          'readonly' => false,
          'after_element_html' => 'Comments',
          'tabindex' => 1
        ));


Multiline Field :
Here is how to add a multiline field to an admin form, with a list of all the options

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


Link :
Here is how to add a link field to an admin form, with a list of all the options

$fieldset->addField('link', 'link', array(
          'label'     => Mage::helper('form')->__('Link'),
          'style'   => "",
          'href' => 'http://jyotiloppy.blogspot.in/',
          'value'  => 'Magento Blog',
          'after_element_html' => ''
        ));


Label :
Here is how to add a label field to an admin form, with a list of all the options

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


Image Upload :
Here is how to add a image upload field to an admin form, with a list of all the options

$fieldset->addField('image', 'image', array(
          'value'     => ' http://jyotiloppy.blogspot.in/image/logo.png',
        ));


File Upload :
Here is how to add a file upload field to an admin form, with a list of all the options

$fieldset->addField('file', 'file', array(
          'label'     => Mage::helper('form')->__('Upload'),
          'value'  => 'Uplaod',
          'disabled' => false,
          'readonly' => true,
          'after_element_html' => 'Comments',
          'tabindex' => 1
        ));


Date Field:
Here is how to add a date field to an admin form, with a list of all the options

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


Checkbox Field:
Here is how to add a checkbox field to an admin form, with a list of all the options

$fieldset->addField('checkbox', 'checkbox', array(
          'label'     => Mage::helper('form')->__('Checkbox'),
          'name'      => 'Checkbox',
          'checked' => false,
          'onclick' => "",
          'onchange' => "",
          'value'  => '1',
          'disabled' => false,
          'after_element_html' => 'Comments',
          'tabindex' => 1
        ));

$fieldset->addField('checkboxes', 'checkboxes', array(
          'label'     => Mage::helper('form')->__('Checkboxs'),
          'name'      => 'Checkbox',
          'values' => array(
                            array('value'=>'1','label'=>'Checkbox1'),
                            array('value'=>'2','label'=>'Checkbox2'),
                            array('value'=>'3','label'=>'Checkbox3'),
                       ),
          'onclick' => "",
          'onchange' => "",
          'value'  => '1',
          'disabled' => false,
          'after_element_html' => 'Comments',
          'tabindex' => 1
        ));




No comments:

Post a Comment