1

In magento admin edit form section, file attribute value is empty. my file buttons code is :-

$fieldset->addField('actionc', 'file', array(
            'label'     => 'Upload',
            'name' =>'actionc',
            'disabled' => false,
            'readonly' => true,
            'tabindex' => 1


        ));

   $form->setValues($model->getData());
    $form->setUseContainer(true);
    $this->setForm($form);

How can I solve this problem.

1 Answer 1

-1

IN your form.php file's _prepareForm() method add 'enctype' => 'multipart/form-data' in $form variable I think you miss that thing

$form = new Varien_Data_Form(array(
        'id' => 'edit_form',
        'action' => $this->getUrl(
            'adminhtml/updatestock/save',
            array(
                '_current' => true,
                'continue' => 0,
            )
        ),
        'method' => 'post',
        'enctype' => 'multipart/form-data'
    ));
    $form->setUseContainer(true);
    $this->setForm($form);

Edit update for Controller

// mychanges
$id = $this->getRequest()->getParam('id');
if($id){
    $objectModel->load($id);
    $imgName = $objectModel->getActionc();
}
// end my changes
$uploader = new Varien_File_Uploader('actionc'); 
$uploader->setAllowedExtensions(array('pdf'));
$uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); 
$path = Mage::getBaseDir('media') . DS . 'pdf' . DS; $imgName = time().$_FILES['actionc']['name']; 
$uploader->save($path, $imgName); 
$postData = $this->getRequest()->getPost(); 
$objectModel = Mage::getSingleton('ghrix_copymerge/merge'); 
$postData['actionc']=$imgName; 
$objectModel->setData($postData)->save();
8
  • Hi Murtuza Zabuawala, its already added $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' )); Commented Feb 13, 2017 at 6:10
  • @KirmalBrar is your problem with edit ?? Commented Feb 13, 2017 at 6:15
  • yes.. when i save the form after edit , it genrates an error. Its just because of browse buttons value is null. Commented Feb 13, 2017 at 6:17
  • @KirmalBrar provide your saveController code Commented Feb 13, 2017 at 6:18
  • $uploader = new Varien_File_Uploader('actionc'); $uploader->setAllowedExtensions(array('pdf')); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $path = Mage::getBaseDir('media') . DS . 'pdf' . DS; $imgName = time().$_FILES['actionc']['name']; $uploader->save($path, $imgName); $postData = $this->getRequest()->getPost(); $objectModel = Mage::getSingleton('ghrix_copymerge/merge'); $postData['actionc']=$imgName; $objectModel->setData($postData)->save(); Commented Feb 13, 2017 at 6:27

Your Answer

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.