8

Here, I would like to upload multiple image in admin panel grid form in magento. I create images upload in admin panel grid form. Here I attached my image upload coding.

[....]
$fieldset->addField('image', 'image', array(
 'name' => 'image',
 'label' => Mage::helper('magentostudy_design')->__('design Image'),
 'title' => Mage::helper('magentostudy_design')->__('design Image'),
 'required' => true,
 'disabled' => $isElementDisabled
 ));
[....]

when i change multiple upload image by using this argument. 'multiple'=> 'multiple' Here my code:

 [....]
 $fieldset->addField('image', 'image', array(
 'name' => 'image',
 'multiple' => 'multiple',
 'mulitple' => true,
 'label' => Mage::helper('magentostudy_design')->__('design Image'),
 'title' => Mage::helper('magentostudy_design')->__('design Image'),
 'required' => true,
 'disabled' => $isElementDisabled
 ));
 [....]

And also i put name value as array[] just like this 'name' => 'image[]',. Nope, i am not getting any result, still single image will be uploaded. How to create multiple image upload concept in magento. Can any one Help me to solve this problem.Please guide me.

asked Oct 2, 2013 at 5:05
3
  • 1
    I'm really interested in this question as well, took a quick look and this block seems to be behind the media uploader for products Mage_Adminhtml_Block_Media_Uploader. I'll follow your question closely :) Commented Oct 2, 2013 at 7:10
  • Adding multiple has no effect because of this: Varien_Data_Form_Element_Abstract::getHtmlAttributes. In there you will find the element attributes that you are allowed to set. Maybe you should write you custom input renderer that allows multiple. Commented Oct 2, 2013 at 7:47
  • 1
    Hi @SanderMangel...Thank you for encourage me..:)- Commented Oct 2, 2013 at 9:57

2 Answers 2

6

Continuing my comment, here is how you can achieve what you need.
You need to create your custom renderer for the image field. For this create this class in your module:

<?php 
class [Namespace]_[Module]_Block_Adminhtml_[Entity]_Helper_Image extends Varien_Data_Form_Element_Image{
 //make your renderer allow "multiple" attribute
 public function getHtmlAttributes(){
 return array_merge(parent::getHtmlAttributes(), array('multiple'));
 }
}

Now at the top of your _prepareForm (where you add your fields) add this line before adding any field:

$fieldset->addType('image', '[Namespace]_[Module]_Block_Adminhtml_[Entity]_Helper_Image');

Or if you want to be "politically correct" add it this way:

$fieldset->addType('image', Mage::getConfig()->getBlockClassName('[module]/adminhtml_[entity]_helper_image'));

This will tell Magento that in your current fieldset, all the fields with type image should be rendered by your own class.

Now you can add your field like similar to how you did it:

$fieldset->addField('image', 'image', array(
 'name' => 'image[]', //declare this as array. Otherwise only one image will be uploaded
 'multiple' => 'multiple', //declare input as 'multiple'
 'label' => Mage::helper('magentostudy_design')->__('design Image'),
 'title' => Mage::helper('magentostudy_design')->__('design Image'),
 'required' => true,
 'disabled' => $isElementDisabled
 ));

That's it.
Don't forget to replace the placeholders ([Module] and others) with your values.
[EDIT]
This is basically the way to override/add any input type you want. Create your own class that should extend the original input class (or Varien_Data_Form_Element_Abstract if you add a new one) and declare it at the top of _prepareForm

answered Oct 2, 2013 at 8:12
8
  • Hi @Marius... Thank u for proper guide..I have one doubt..which is refer [Entity] and entity given in class? can you please explain it... Commented Oct 2, 2013 at 9:55
  • @VIVEK-MDU. Entity is what you are editing. it can be a product, an article...What is the class name of your form? From that I can tell you what entity should be. In theory it can be anything. You can even remove that from the class name but I added it there to keep a consistency in the code. Commented Oct 2, 2013 at 11:11
  • @Marius for multiple i have to create separate file button to upload image ? or how it can handle multiple image Commented Mar 8, 2014 at 7:58
  • @Marius : This didn't work for me. Still load one image upload. Please any suggestions on it? Commented Apr 7, 2015 at 17:05
  • 1
    Excellent ! This question should be protected Commented Oct 20, 2016 at 16:13
1

I use this method to make the same thing but with module Aw_blog but when I add the

$fieldset->addType('image', Mage::getConfig()->getBlockClassName('aw_blog/adminhtml_blog_helper_image'));

The page form for my post's blog is white.

PS: the field upload one image is a success but for multiple don't.

mymodule enter image description here

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
answered Mar 6, 2020 at 16:56

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.