1

How to create Magento admin custom module click add field button for entity select type 'file' for the new attribute

This is form code:

$fieldset->addField('uploadpdf', 'file', array(
        'label' => Mage::helper('promotionsoffers')->__('Upload PDF'),
        'name'  => 'uploadpdf',

    ));`
Vinoth
  • 77
  • 1
  • 1
  • 4

1 Answers1

1

This is a simple example of Multiple File Upload

To achieve similar through Magento's Form Library, we will modify its code a bit in this way

Modify getElementHtml method of lib/Varien/Data/Form/Element/Abstract.php

public function getElementHtml()
{
    if($this->getType()=='file' && $this->getMultiple())
        $_multiple = ' multiple';
    $html = '<input id="'.$this->getHtmlId().'" name="'.$this->getName()
         .'" value="'.$this->getEscapedValue().'" '.$this->serialize($this->getHtmlAttributes()).$_multiple.'/>'."\n";
    $html.= $this->getAfterElementHtml();
    return $html;
}

and then just pass new attribute multiple=>true in you field declaration like this

$fieldset->addField('uploadpdf', 'file', array(
    'label' => Mage::helper('promotionsoffers')->__('Upload PDF'),
    'name'  => 'uploadpdf[]',
    'multiple'=>true
));
Community
  • 1
  • 1
Deependra Singh
  • 1,464
  • 15
  • 28