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'));
    }
}
3

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.

Your Answer

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

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