I need to add a button in my custom module admin form , which calls an action 'upload'

How can I achieve it ?

  • Can you give more details on what you are trying to achieve? – Marius Aug 28 '13 at 11:26
  • I have made a custom module which needs Multiple images to be uploaded for each item , I want to add Upload Images button on my form , so that I can save images before form submit – user2081039 Aug 28 '13 at 12:04

When defining a form element you have the option of specifying after_element_html. what you put there will be shown after the element itself. Here is an example:

$fieldset->addField('some_field', 'text', array(
    'label' => Mage::helper('core')->__('Some label'),
    'name'  => 'some_name',
    'after_element_html' => '<button type="button" onclick="alert(\'Stop clicking me!!\')">Do not click</button>' 

I think you can start from here. you can use the onclick on the button to do an ajax call (or something like that) and upload your image.

  • very cool! never knew this – CodingMageSheen May 3 '17 at 17:54
  • if you do not want to display text field, then you can use type 'note' instead of 'text' – Jiří Chmiel Dec 14 '18 at 13:50

For system=>configuration:

In your system.xml you can add Form-Elements. There are 3 relevant nodes:

  • frontend_type - corresponding to /lib/Varien/Data/Form/Element
  • source_model
  • backend_model

I know that you can build your own source- and so I believe backend_model. It is relative easy to do it. Just add the classpath to your nodevalue like "adminhtml/system_config_source_yesno".

If you have a look to /lib/Varien/Data/Form/Element, you can see File.php which you can use to build the Upload-Frontendtype.

For other admin-sections:

You can use extend Mage_Adminhtml_Block_Widget_Form and Hmx_Incopay_Block_Widget_Container

In your widget form you can add the following in the constructor:

$form = new Varien_Data_Form(array(
                                    'id' => 'edit_form',
                                    'action' => $this->getUrl('*/*/edit', array(
                                            'id' => $this->getRequest()->getParam('id')
                                    'method' => 'post',
                                    'enctype' => 'multipart/form-data'


$fieldset->addField(Mage::getStoreConfig('XXXX/input_file_name'), 'file', array(
            'name' => Mage::getStoreConfig('XXXX/input_file_name'),
            'label' => __('CSV account data'),
            'class' => 'required-entry',
            'required' => true,

Dont change the form-id and beware of some other conventions listed here http://blog.kervinramen.com/2012/10/how-magento-widget-form-container.html


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.