Code For Add Custom Field In From In Magento
Hi magento friends in this blog post im share with you to multiple type of fields on form to in admin block in magento2 . this is code you are directly use in your project file
use this code in your form in magento :
1) Text Field
if you are add text Field in form to copy code and paste your form file :
$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
if you are add Text Area Field in form to copy code and paste your form file
$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
if you are add Password Field in form to copy code and paste your form file
$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
if you are add Obscure Password Field in form to copy code and paste your form file
$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
if you are add Radio Button Field in form to copy code and paste your form file
$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
if you are add Checkbox Field in form to copy code and paste your form file
$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
if you are add Dropdown Field in form to copy code and paste your form file
$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
if you are add Dropdown v2 Field in form to copy code and paste your form file
$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
if you are add Multiselect Field in form to copy code and paste your form file
$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
if you are add Multiline Field in form to copy code and paste your form file
$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
if you are add Lable Field in form to copy code and paste your form file
$fieldset->addField('label', 'label', array(
'value' => $this->__('Label Text'),
));
12) Link
if you are add Link Field in form to copy code and paste your form file
$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
if you are add Note Field in form to copy code and paste your form file
$fieldset->addField('note', 'note', array(
'text' => $this->__('Hello galaxy!'),
));
14) Submit Button
if you are add Submit Button Field in form to copy code and paste your form file
$fieldset->addField('submit', 'submit', array(
'label' => $this->__('Submit'),
'required' => true,
'value' => 'Submit',
'after_element_html' => '<small>Comment</small>',
'tabindex' => 15
));
15) Time
if you are add Time Field in form to copy code and paste your form file
$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
if you are add File Upload Field in form to copy code and paste your form file
$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
if you are add Image Upload Field in form to copy code and paste your form file
$fieldset->addField('image', 'image', array(
'value' => 'http://brymayor.com/wp-content/uploads/2013/02/default-logo.png',
));
18) Date
if you are add Date Field in form to copy code and paste your form file
$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
));