Quantcast
Viewing all articles
Browse latest Browse all 10

List of Magento Admin Form Fields

On our previous post, we learned how to create Magento Adminhtml grids. All the codes below should be written in the class Foo_Bar_Block_Adminhtml_Baz_Edit_Form (assuming it doesn’t have tabs) inside the _prepareForm() function.

Text Field

$fieldset->addField('title', 'text', array(
    'label'     => $this->__('Title'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => 'This is text...',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "alert('On Click');",
    'onchange'  => "alert('On Change');",
    'style'     => "border:5px",
    'after_element_html' => '<small>Comment<small>',
    'tabindex'  => 1
));

Text Area

$fieldset->addField('textarea', 'textarea', array(
    'label'     => $this->__('TextArea'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => '',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));

Password

$fieldset->addField('password', 'password', array(
    'label'     => $this->__('Password'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'style'     => "",
    'value'     => 'mojojojo',
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));

Obscure Password

$fieldset->addField('obscure', 'obscure', array(
    'label'     => $this->__('Obscure'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'obscure',
    'value'     => '04021993',
    'onclick'   => "",
    'onchange'  => "",
    'style'     => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));

Radio Button

$fieldset->addField('radio', 'radio', array(
    'label'     => $this->__('Radio'),
    'name'      => 'title',
    'value'     => '1',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",          
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));

$fieldset->addField('radio2', 'radios', array(
    'label'     => $this->__('Radios'),
    'name'      => 'title',
    'values'    => array(
                      array('value'=>'1','label'=>'Radio1'),
                      array('value'=>'2','label'=>'Radio2'),
                      array('value'=>'3','label'=>'Radio3'),
                 ),
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'value'     => '2',
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));

Checkbox

$fieldset->addField('checkbox', 'checkbox', array(
    'label'     => $this->__('Checkbox'),
    'name'      => 'Checkbox',
    'checked'   => false,
    'value'     => '1',
    'disabled'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 3
));
$fieldset->addField('checkboxes', 'checkboxes', array(
    'label'     => $this->__('Checkboxes'),
    'name'      => 'Checkbox',
    'value'     => '2',
    'values'    => array(
                      array('value'=>'1','label'=>'Checkbox1'),
                      array('value'=>'2','label'=>'Checkbox2'),
                      array('value'=>'3','label'=>'Checkbox3'),
                 ),
    'onclick'   => "",
    'onchange'  => "",
    'disabled'  => false,
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 4
));

Dropdown

$fieldset->addField('select', 'select', array(
    'label'     => $this->__('Select'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => '1',
    'values'    => array('-1'=>'Please Select','1' => 'Option1', '2' => 'Option2', '3' => 'Option3'),
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));

Dropdown v2

$fieldset->addField('select2', 'select', array(
    'label'     => $this->__('Select v2'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'value'     => '4',
    'values'    => array(
                          '-1'=>'Please Select..',
                          '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'   
                                 ),                                          

                     ),
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));

Multiselect

$fieldset->addField('multiselect2', 'multiselect', array(
    'label'     => $this->__('Select Type2'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'onclick'   => "return false;",
    'onchange'  => "return false;",
    'disabled'  => false,
    'readonly'  => false,
    'value'     => '3',
    'values'    => array(
                          '-1'=> array( 'label' => 'Please Select..', 'value' => '-1'),
                          '1' => array( 
                                   'value'=> array(array('value'=>'2' , 'label' => 'Option2') , array('value'=>'3' , 'label' =>'Option3') ),
                                   'label' => 'Color'    
                                 ),
                          '2' => array( 
                                   'value'=> array(array('value'=>'4' , 'label' => 'Option4') , array('value'=>'5' , 'label' =>'Option5') ),
                                   'label' => 'Size'   
                                 ),                                          

                     ),
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 10
));

Multiline

$fieldset->addField('multiline', 'multiline', array(
    'label'     => $this->__('Multi Line'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => 'Hello galaxy!',
    'disabled'  => false,
    'readonly'  => false,
    'onclick'   => "",
    'onchange'  => "",
    'style'     => "border:5px",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 1
));

Label

$fieldset->addField('label', 'label', array(
    'value'     => $this->__('Label Text'),
));

Link

$fieldset->addField('link', 'link', array(
    'label'     => $this->__('Link'),
    'style'     => "",
    'href'      => 'http://www.brymayor.com/',
    'value'     => 'My Blog',
    'after_element_html' => '<small>Comment</small>',
));

Note

$fieldset->addField('note', 'note', array(
    'text'     => $this->__('Hello galaxy!'),
));

Submit Button

$fieldset->addField('submit', 'submit', array(
    'label'     => $this->__('Submit'),
    'required'  => true,
    'value'     => 'Submit',
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 15
));

Time

$fieldset->addField('time', 'time', array(
    'label'     => $this->__('Time Title'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'title',
    'value'     => '04,00,00',
    'onclick'   => "",
    'disabled'  => false,
    'readonly'  => false,
    'onchange'  => "",
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 3
));

File Upload

$fieldset->addField('file', 'file', array(
    'label'     => $this->__('Uploader'),
    'value'     => 'Uploader',
    'disabled'  => false,
    'readonly'  => false,
    'after_element_html' => '<small>Comment</small>',
    'tabindex'  => 5
));

Image Upload

$fieldset->addField('image', 'image', array(
    'value'     => 'http://brymayor.com/wp-content/uploads/2013/02/default-logo.png',
));

Date

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

 

All the different type of form fields available in Magento can be found in lib/Varien/Data/Form/Element.

 

The post List of Magento Admin Form Fields appeared first on BryMayor.com.


Viewing all articles
Browse latest Browse all 10

Trending Articles