php - Magento Custom Module: multiple Image Uploader in adminhtml form -
i have created adminhtml module working fine. in create new item form there 4 field name , images, url , email id;
i have used file uploader upload images . working fine not able upload multiple images.
is possible have multiple image uploader? here simple image uploader code.
if(isset($data['image']) && $data['image'] != ''){ $finderlink = mage::getbaseurl(mage_core_model_store::url_type_media) .'finder/store_locator/'.$data['image']; $findername = $data['image']; $fieldset->addfield('imagelabel', 'label', array( 'label' => mage::helper('finder')->__('location image'), 'name' =>'image', 'value' => $finderlink, 'after_element_html' => '<img src="'.$finderlink .'" alt=" '. $findername .'" height="120" width="120" />', )); $fieldset->addfield('image', 'image', array( 'label' => mage::helper('finder')->__('change image'), 'required' => false, 'name' => 'image', )); }else{ $fieldset->addfield('image', 'image', array( 'label' => mage::helper('finder')->__('image'), 'required' => false, 'name' => 'image', )); }
i need have multiple image uploader in custom module.
you need create custom renderer image field. create class in module:
<?php class [namespace]_[module]_block_adminhtml_[entity]_helper_image extends varien_data_form_element_image{ //make renderer allow "multiple" attribute public function gethtmlattributes(){ return array_merge(parent::gethtmlattributes(), array('multiple')); } }
now @ top of _prepareform
(where add fields) add line before adding field:
$fieldset->addtype('image', '[namespace]_[module]_block_adminhtml_[entity]_helper_image');
or if want "politically correct" add way:
$fieldset->addtype('image', mage::getconfig()->getblockclassname('[module]/adminhtml_[entity]_helper_image'));
this tell magento in current fieldset, fields type image
should rendered own class.
now can add field similar how did it:
$fieldset->addfield('image', 'image', array( 'name' => 'image[]', //declare array. otherwise 1 image uploaded 'multiple' => 'multiple', //declare input 'multiple' 'label' => mage::helper('helper_alias')->__('image'), 'title' => mage::helper('helper_alias')->__('image'), 'required' => true, ));
that's it.
don't forget replace placeholders ([module]
, others) values.
this way override/add input type want. create own class should extend original input class (or varien_data_form_element_abstract
if add new one) , declare @ top of _prepareform
Comments
Post a Comment