1

My form contain a file field for image uploading.

   protected function _prepareForm()
   {
       $form = new Varien_Data_Form();
       $this->setForm($form);
       $fieldset = $form->addFieldset('image_form', array('legend'=>'Image  Informations'));

        $fieldset->addField('img_label', 'text',
                       array(
                          'label' => 'Label',
                          'class' => 'required-entry',
                          'required' => true,
                          'name' => 'img_label',

                    ));
        $fieldset->addField('img_src', 'file',
                         array(
                             'label' => 'Upload Image',
                             'class' => 'required-entry',                      
                             'required' => false,
                             'name' => 'img_src',
                            ));

        $fieldset->addField('img_desc', 'textarea',
                    array(
                        'label'     => 'Description',
                        'required' => false,
                        'name' => 'img_desc',
                 ));

        $fieldset->addField('img_link', 'text',
                    array(
                        'label'     => 'Link',
                        'required' => false,
                        'name' => 'img_link',
                ));

 if ( Mage::registry('image_data') )
 {
    $form->setValues(Mage::registry('image_data')->getData());
  }
  return parent::_prepareForm();
 }

I only save the file name in my DB, not the whole URL, and whene i'm editing, the field value contain just the image name. If I do not make any changes (image) :

  • Magento validation detect the field as empty.

Can you help please !
Thanks

t.c
  • 1,255
  • 1
  • 16
  • 36

1 Answers1

0

Try changing addField('img_src', 'file'... to

$fieldset->addField('img_src', 'image', array(
      'label'     => Mage::helper('tag')->__('Upload Image'),
      'required'  => true,
      'name'      => 'img_src',
));
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
  • no ! whene I inspect the page i got this : – t.c Jan 07 '13 at 13:52
  • After saving, what value is in 'img_src' in your database? – MagePal Extensions Jan 07 '13 at 13:55
  • Not sure what you mean by 'i'm saving just the last part', but the value in you db table should be something like 'catalog/category/1clown_boom_cover.jpg' – MagePal Extensions Jan 07 '13 at 14:19
  • the value in my db is "1clown_boom_cover.jpg", it's not a product image, but a slider extension. – t.c Jan 07 '13 at 14:46
  • I think the problem have to do with where the file is store on the file system. Try manually updating the db and change it `slider_img\1clown_boom_cover.jpg`... if that work then take a look @ http://stackoverflow.com/questions/2931687/addfield-type-image-and-thumbnail-path – MagePal Extensions Jan 07 '13 at 14:57
  • I got the same result ! and i've found this , http://stackoverflow.com/questions/5903323/cant-get-value-of-input-type-file – t.c Jan 07 '13 at 15:57