Friday 4 October 2013

Code For Add Custom Field In From In Magento

Put this code in your module form.php file

1) 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
));
       

2) 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
));

3) 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
));

4) 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
));

5) 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
));

6) 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
));

7) 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
));

8) 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
));

9) 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
));

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
));

11) Label


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

12) Link


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

13) Note


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

14) Submit Button


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

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
));

16) File Upload


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

17) Image Upload


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

18) 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
));

No comments:

Post a Comment