3

I am trying to add the magento image uploader to my custom admin module. After tracking it down in the code base and getting very confused as to where and how it is all generated I searched on google and found this and this. My issue is the way I have followed these instruction I end up with a choose file button adding image to admin area what I am trying to achieve is magento default image uploader

I was expecting this to be a straight forward below is what I have

class Namesapce_Module_Block_Adminhtml_ShopLocator_Edit_Tab_Media extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
 $form = new Varien_Data_Form(array(
 'id' => 'edit_form',
 'action'=> $this->getUrl('*/*/save',
 array('id' => $this->getRequest()->getParam('id'))),
 'method'=> 'post',
 'enctype' => 'multipart/form-data'
 )
 );
 $fieldset = $form->addFieldset('general_form', array(
 'legend' => $this->__('Add Media')
 ));
 $fieldset->addType('image', Mage::getConfig()->getBlockClassName('namespace_module/adminhtml_shoplocator_helper_image'));
 ...otherFields
 $fieldset->addField('image', 'image', array(
 'label' => $this->__('Add New Image'),
 'required' => false,
 'name' => 'image[]',
 'multiple' => 'multiple',
 'multiple' => 'multiple'
 ));
 ...otherFields
 }
protected function _getFormData()
{
 $data = Mage::getSingleton('adminhtml/session')->getFormData();
 if (!$data && Mage::registry('current_shop')->getData()) {
 $data = Mage::registry('current_shop')->getData();
 }
 return (array) $data;
}
}

.

class Namespace_Module_Block_Adminhtml_ShopLocator_Helper_Image extends Varien_Data_Form_Element_Image
{
 public function getHtmlAttributes()
 {
 return array_merge(parent::getHtmlAttributes(), array('multiple'));
 }
}
asked May 21, 2014 at 7:53
3
  • I have followed this tutorial, which seems to work fine: stackoverflow.com/questions/5077755/images-in-magento-widgets Commented Jul 2, 2014 at 12:58
  • Have you tired looking into the block Mage_Adminhtml_Block_Media_Uploader Commented Jul 24, 2014 at 7:41
  • Did you ever get this sorted Tony? Commented Sep 15, 2015 at 5:43

1 Answer 1

1

please check this link

https://wiki.magento.com/display/m1wiki/How+to+create+an+image+or+video+uploader+for+the+Magento+Admin+Panel

you should use

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

I hope this will help you.

answered Dec 22, 2015 at 7:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.