I am using Zend Framework 1.11 and after editing a record, the image file fields is emptied as well even though no other image is uploaded.
I have solved before this problem with mysql using this in the sql query:
image=ifnull(%s, image)
And worked perfectly. I am working with Zend now and I am not sure how this can be done. Anybody can help please?
Controller code:
$input = $form->getValues();
$item = Doctrine::getTable('Tcc_Model_Item')
->find($input['article_id']);
$item->fromArray($input);
$item->save();
Update is done using a doctrine model.
form field is:
$image = new Zend_Form_Element_File('image');
$image->setLabel('Image')
->addValidator('IsImage')
->setDestination('../public/uploads')
->addValidator('Size', false, '404800')
->addValidator('Extension', false, 'jpg,png,gif')
->addValidator('ImageSize', false, array(
'minwindth' => 50,
'minheight' => 50,
'maxwidth' => 250,
'maxheight' => 250))
->setOptions(array('class' => 'create'));
I thought to answer to my own question since I found a solution myself that my be of help to some else.
So what I did to solve this problem is:
added an hidden field to the form used to edit like this:
$image = new Zend_Form_Element_Hidden(‘image’);
changed to image file field (the new image to upload) with a different name like this:
$image2 = new Zend_Form_Element_File(‘image2’);
This way when editing the hidden field will contain the info of the “image” field if there is one.
Then in the controller I simply have a if/else statement just before the save() like this:
Hope it helps others with same issue.