Maybe I'm missing something, but unless there's a really good reason to wrap
the image element in a form I wouldn't do this because it is not the most
simple solution. Anytime complexity is added there should be justification.
While this may not seem like a big deal, the sum of all complexity added
unjustifiably to your application would make the application more difficult
to maintain than it needs to be. The most simple solution to in my opinion
would be a single form and a little view logic.


gerardroche wrote:
> 
> What i do is display the file upload element and if an image is already
> uploaded display the image and a notice above the file upload element with
> "if you upload a new image it will replace the current one". You can use
> the populate method to do the logic. 
> 
> There's probably a better way but this works for me. 
> 
> e.g. 
> 
> You have 2 Form Classes 
> 
> 1. Form_Add_Image extends Zend_Form
> 
> 2. Form_Update_Image extends Form_Add_Image 
> 
> 
> In Form_Update_Image::populate
> 
>     public function populate(array $values)
>     {
> 
>         if ($values['image_id']) {
>             $imageId = $values['image_id'];
> 
>             $images = new Images();
>             $i = $images->find($imageId)->current();
>             $url = '/images/gallery' . $i->url . $i->file_name . '.' .
> $i->extension;
> 
>             $this->getElement('image')
>                  ->setDescription('Uploading an image will replace the
> current one.');
> 
>             $imageElementDecorators = array(
>                 array('Description', array('escape' => false)),
>                 'Errors',
>                 'ViewHelper',
>                 array('Label'),
>                 array('HtmlTag', array('tag' => 'li'))
>             );
>             
>             $this->getElement('image_status')
>                  ->setDecorators($imageElementDecorators)
>                  ->setDescription('< img src="' . $url . '"  />');
>         }
>         
>         return parent::populate($values);
>     }
> 
> Hope this helps.
> 
> 
> Edward Haber wrote:
>> 
>> Definitely view logic. Good call. Still I'm uncertain though because  
>> I'm working with an extended Zend_Form class. Perhaps I should make a  
>> custom Form Element? Or a custom Form Decorator? Or use the view  
>> helper decorator for just that element? I'd love to hear the Zend best  
>> practice take on this solution.
>> 
>> Thanks!
>> 
>> 
>> 
>> On Oct 2, 2008, at 10:50 PM, Matthew Lurz wrote:
>> 
>>>
>>> Sounds like view logic to me and so I would add a conditional in the  
>>> view
>>> script.
>>>
>>>
>>> Edward Haber wrote:
>>>>
>>>> I have a form that I want offer an image upload form element on. This
>>>> has worked great using Zend_Form_Element_File. The upload works fine.
>>>> What is the recommended way to have the uploaded image replace the
>>>> upload form if an image exists? I don't need the solution coded, just
>>>> the direction I should go.
>>>>
>>>> For example, I have the form as a class. SHould I pass the image name
>>>> (if one exists) in the config array to the form? In the form i would
>>>> then check for $config['imageName'] and if it exists display the  
>>>> image
>>>> in place of the form element. This is another trick - how do display
>>>> an image in a form?
>>>>
>>>> Is the answer toggling in the form class between the form element and
>>>> an image? Or using CSS to display the image if it's there and "hide"
>>>> the form (display:none for example).
>>>>
>>>> I'm just looking for best practice. I'm sure lots of people have
>>>> already confronted this situation. Any input much appreciated!  
>>>> Thanks!
>>>>
>>>> Eddie
>>>>
>>>>
>>>>
>>>>
>>>
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/Toggle-file-upload-element-with-uploaded-image-tp19780259p19791263.html
>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>
>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Toggle-file-upload-element-with-uploaded-image-tp19780259p19796491.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to