Hi Laurent,

laurent5la wrote:
> 
> I was wondering if someone used Zend_Form_Element_File.
> 
> I need to create a form with a File upload button.
>  input name="uploadFile1" type="file" id="uploadFile1"
> 

as the file-element isn't implemented yet in the Zend_Form component, you
could fake it yourself by doing a quick and dirty hack right into the
Zend/Form/Decorator. Create a new Decorator and call it i.e.
"UploadWrapper":

class Zend_Form_Decorator_UploadWrapper extends Zend_Form_Decorator_Abstract
{
    public function render($content)
    {
          return "<input type="file" name="FileUpl" id="FileUpl"/> .....";
    } 
}

notice, in this case you simply ignore $content, which would be the rendered
stuff that comes from the ZF itself. 

then you can simply write sth. like this in your controller (or as in this
case, in your form-class, that extends Zend_Form):

        $Upl = new Zend_Form_Element_Text('FileUpl');
        $Upl->setLabel('Upload:')
                ->setDecorators( array(
                                    array('ViewHelper', array('helper' =>
'formFile')),
                                    array('Label', array('style' =>
'display:block;')),
                                    array('UploadWrapper')
                                 )
                               );
and add the element to the form via $this->addElement(array($FileUpl));


Not a good solution, but it works (at least in over here and at the moment
of writing this ;))

best

-Wolfgang

--
German Servicepoint for PHP since 1999: Dynamic Web Pages:
http://www.dynamic-webpages.de/
 
PHP-Training & Certification http://www.phpzertifizierung.eu/

-- 
View this message in context: 
http://www.nabble.com/Zend_Form-with-file-upload-field-tp15326842s16154p15334963.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to