16
2009
Add custom input fields on Admin html forms in Magento
Adding a custom input type on the forms on Admin html is very easy.
I used this in the module which I created with Module Creator.
I supposed to show the uploaded image on the edit form on Admin. The images are uploaded by the user from the front end.
For displaying the thumbnail, by default there is no way in Magento.
So I created a new class ‘Varien_Data_Form_Element_Thumbnail’ & named it Thumbnail.php.
class Varien_Data_Form_Element_Thumbnail extends Varien_Data_Form_Element_Abstract
{
public function __construct($data)
{
parent::__construct($data);
$this->setType('file');
}
public function getElementHtml()
{
$html = '';
if ($this->getValue()) {
$url = $this->_getUrl();
if( !preg_match("/^http\:\/\/|https\:\/\//", $url) ) {
$url = Mage::getBaseUrl('media') . $url;
}
$html = '
';
}
$this->setClass('input-file');
$html.= parent::getElementHtml();
return $html;
}
protected function _getUrl()
{
return $this->getValue();
}
public function getName()
{
return $this->getData('name');
}
}
Copy the file at ‘/lib/Varien/Data/Form/Element/’.
To Display the thumbnail, inside the function _prepareForm() write the code below. (In my case I edited the file.. ‘app/code/local/Mage/Modulename/Block/Adminhtml/Modulename/Edit/Tab/Form.php’. This module was created with Module Creator)
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('modulename_form', array('legend'=>Mage::helper('modulename')->__('Module information')));
$tempArray = array(
'label' => Mage::helper('arequets')->__('Sample Work'),
'name' => 'samplefilename',
'style' => 'display:none;',
);
$fieldset->addField('samplefilename', 'thumbnail',$tempArray);
Here, ‘samplefilename’ should be the path of the thumbnail.
Related Posts
-
http://www.downselot.com/ AlexAxe
-
admin
-
jara
-
admin
-
jara
-
admin
-
jara
-
Andy
-
admin
-
http://mcdonaldscouponsnews.wikispaces.com mcdonalds coupons
-
Ronald
-
http://www.bjergdesign.dk/ chandresh
-
http://www.gtechonline.co.uk sweeper
-
admin
-
Sumanta Pati
-
kurt
-
Anonymous
-
http://www.tellsys.com buy seo services
-
Vasanth

An article by