I need to add a button in my custom module admin form , which calls an action 'upload'
How can I achieve it ?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
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.
In your system.xml you can add Form-Elements. There are 3 relevant nodes:
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