Magento: Adding a Custom Form Element to an Adminhtml Form

Ecommerce Marketing
How does marketing make the leap into eCommerce?
September 12, 2014
Apple Pay – the future of mobile wallets
October 21, 2014
Show all

Magento: Adding a Custom Form Element to an Adminhtml Form

Magento admin

You want to manipulate the value of a standard text field. One of the most common solutions for doing this is to add a custom form element to your adminhtml form. This can be done by creating your own element class and extending the Varien_Data_Form_Element_Abstract. This method will work, but seems a bit much just to manipulate the value.

I dug around a bit and found a perfect solution. Varien_Data_Form_Abstract provides a nifty method “addType“. So just before we add our new form field, we would need to add the new element type:

The class “Fontera_Trader_Block_Adminhtml_Games_Edit_Tab_Renderer_Price” will look like this:

The class “Fontera_Trader_Block_Adminhtml_Games_Edit_Tab_Renderer_Price” can extend any one of the defined element types in “lib/Varien/Data/Form/Element/” or you could just extend “Varien_Data_Form_Element_Abstract” and create your own element type.

Thats it…