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
I found the solution.
To add a country multi select dropdown in your form you need to add below code in your Block/Adminhtml/ModuleName/Edit/Tab/Form.php
file.
$countryList = Mage::getModel('directory/country')->getResourceCollection()->loadByStore()->toOptionArray(true);
$fieldset->addField('countries', 'multiselect', array(
'name' => 'countries[]',
'label' => Mage::helper('zones')->__('Countries'),
'title' => Mage::helper('zones')->__('Countries'),
'required' => true,
'values' => $countryList,
));
Best Answer
First thing is first. You cannot upload images through AJAX.
You have to trick the browser (or the user).
take a look at how the category images are uploaded in
app/design/adminhtml/default/default/template/catalog/category/edit/form.phtml
.The idea is to have an
iframe
in your DOM with and id (let's say 'trickIframe') and make that form submit to that iframe.Then you can handle the post request in the save method and that method should return some javascript code for refresing (or replace page content or what ever) just like
Mage_Adminhtml_Catalog_CategoryController::saveAction
does.