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.

0

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();
  • 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' )); – Kirmal Brar Feb 13 '17 at 6:10
  • @KirmalBrar is your problem with edit ?? – Murtuza Zabuawala Feb 13 '17 at 6:15
  • yes.. when i save the form after edit , it genrates an error. Its just because of browse buttons value is null. – Kirmal Brar Feb 13 '17 at 6:17
  • @KirmalBrar provide your saveController code – Murtuza Zabuawala Feb 13 '17 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(); – Kirmal Brar Feb 13 '17 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.