You'll surely get many forum of admin field in magento form. So, I'm showing you in a different way. You need to write this code in your module app/code/(local/community)/Companyname/Modulename/Block/Adminhtml/Modulename/Edit/Tab/Form.php
Find the method _prepareForm() and add which field you want to add.
How to add Text Field :
>> $fieldset->addField('fieldName', 'text', array(
'label' => Mage::helper('form')->__('Banner Name'),
'class' => 'required-entry',
'required' => true, // true,false
'name' => 'name',
'onclick' => "alert('add javascript if neeed');",
'onchange' => "alert('add javascript if neeed');",
'style' => "width:15px",
'value' => 'Default value',
'disabled' => false, // true,false
'readonly' => true, // true,false
'after_element_html' => '<small>Add any html or javascript</small>',
));
You can also add field attribute(e.g. label, class, name) like this way.
>> $textFiled = $fieldset->addField('fieldName', 'text');
$textFiled->setName("name");
$textFiled->setLabel(Mage::helper('form')->__('Banner Name'));
$textFiled->setAfterElementHtml('
<script>
function customFunction(element){
alert(element.value);
}
</script>
');
$textFiled->setOnclick("customFunction(this)");
Same thing will applicable for Max types of form field with a small changes.
Time >> $fieldset->addField('fieldName', 'time');
TextArea >> $fieldset->addField('fieldName', 'textarea');
Date >> $fieldset->addField('fieldName', 'date', array(
'label' => Mage::helper('form')->__('Date'),
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
));
Submit Button >> $fieldset->addField('submit', 'submit');
DropDown >> $fieldset->addField('fieldName', 'select', array(
'label' => Mage::helper('form')->__('Select'),
'values' => array('0'=>'Please Select','1' => 'Option1','2' => 'Option2', '3' => 'Option3'),
));
Drop down with optiongroup
>> $fieldset->addField('fieldName', 'select', array(
'label' => Mage::helper('form')->__('Select Value'),
'values' => array(
'0'=>'Please Select',
'1' => array(
'value'=> array(array('value'=>'2' , 'label' => 'Option2') , array('value'=>'3' , 'label' =>'Option3') ),
'label' => 'Length'
),
'2' => array(
'value'=> array(array('value'=>'4' , 'label' => 'Option4') , array('value'=>'5' , 'label' =>'Option5') ),
'label' => 'Type'
),
),
));
Radio Button >> $fieldset->addField('fieldName', 'radio');
Multi Radio Button >> $fieldset->addField('fieldName', 'radios', array(
'values' => array(
array('value'=>'1','label'=>'Radio1'),
array('value'=>'2','label'=>'Radio2'),
array('value'=>'3','label'=>'Radio3'),
),
));
Password Field >> $fieldset->addField('fieldName', 'password');
Note >> $fieldset->addField('fieldName', 'note');
Multiselect >> $fieldset->addField('fieldName', 'multiselect', array(
'values' => array(
'0'=> array( 'label' => 'Please Select', 'value' => '0'),
'1' => array(
'value'=> array(array('value'=>'2' , 'label' => 'Option2') , array('value'=>'3' , 'label' =>'Option3') ),
'label' => 'Length'
),
'2' => array(
'value'=> array(array('value'=>'4' , 'label' => 'Option4') , array('value'=>'5' , 'label' =>'Option5') ),
'label' => 'Type'
),
),
));
Multiline >> $fieldset->addField('fieldName', 'multiline');
Link >> $fieldset->addField('fieldName', 'link', array('href' => 'https://www.facebook.com/onestepmagentosolutions'));
Label >> $fieldset->addField('fieldName', 'label');
Image Upload >> $fieldset->addField('fieldName', 'image');
File Upload >> $fieldset->addField('fieldName', 'file');
Checkbox >> $fieldset->addField('fieldName', 'checkbox');
Multi Checkbox >> $fieldset->addField('fieldName', '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'),
),
));