Quantcast

Zend_Form File Element / Decorator - Extremely Confuzzled

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Zend_Form File Element / Decorator - Extremely Confuzzled

               
I would like to get it outside of those dt/dd tags (which suggest the default ZF Decorators are being applied).
ZF Documentation I find stragely lacking in the various methods/variables/parameters to use. If anyone knows of a better reference, it's sure to help a great deal.

I would greatly appreciate any help anyone can provde me on this.
Thanks~
Jayawi
Hi there~

I'm relatively new to ZF but have enjoyed using it so far. The main issue I've had with ZF is with it's Form and Decorator aspects. After going through God knows how many articles/blogs/posts and what not, I thought I finally had a grasp of it. Things were working okay.

I created a standard set of decorators (for Elements, Buttons and Forms) based on an example I saw. Recently however, I realised that I needed to add in some File Input fields into one of the forms. None of the above decorators worked with it. At which point, I decided to use ViewScripts on all the forms since it provides greater room to stylise/organise the form.

The code I'm currently using, looks something like the following:

site/application/forms/RegisterForm.php
class RegisterForm extends Zend_Form
{
        public function init ()
        {
                $this->setAction('')
                                ->setMethod('post')
                                ->setAttrib('id','formStartProject')
                                ->setAttrib('enctype', 'multipart/form-data');

                $this->addElement('text', 'textName', array('label' => 'Given Name'));
                $oName = $this->getElement('textName')
                                                ->setRequired(true)
                                                ->setDecorators(array('ViewHelper', 'Errors'));

                $this->addElement('file', 'filePhotograph');
                $oPhotograph = $this->getElement('filePhotograph')
                                                ->setRequired(true);

                $this->addElement('submit', 'submitRegister', array('label' => 'Done'));
                $oContactPersonSubmit = $this->getElement('submitRegister');
                $oContactPersonSubmit->setDecorators(array('ViewHelper', 'Errors'));
               
                $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/RegisterForm.phtml'))));
        }
}

site/application/views/scripts/forms/RegisterForm.phtml
<div id='iDivRegister'>
        <form action='' method='post'>
                                                                                                                                                                                                                                                                                                                                                                               
<label for='textName'>Name:</label><?php echo $this->element->textName; ?>
<label for='filePhotograph'>Photo:</label><?php echo $this->element->filePhotograph; ?>
<?php echo $this->element->submitRegister; ?>
        </form>
</div>

From RegisterForm.php I had to change $this->addElement('file', 'filePhotograph', array('label' => 'Photo')); to get it to work. prior to that, the File Input element was being displayed twice.
Additionally, if ->setDecorators(array('ViewHelper', 'Errors')) was attached to the File Input object, it would throw the error "Warning: No file decorator found... unable to render file element in C:\xampp\xampp\php\PEAR\Zend\Form\Element.php on line 1929".
I honestly can't understand what the issue is or how I'm supposed to resolve it. All the searching and reading I did lead me to more questions and no solution. Some of them dealt with the lack of a File Input Class in ZF (which I believe was a somewhat early release), while others used custom classes for things which didn't really clarify anything for me.

Currently, the File Input Element is rendered as follows:
<label for='filePhotograph'>Photo:</label>                <dt id="filePhotograph-label"> </dt>
                <dd><input type="file" name="filePhotograph" id="filePhotograph"></dd>
       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Form File Element / Decorator - Extremely Confuzzled

latterd


2009/9/9 Daniel Latter <[hidden email]>
Hi,

Have a look at this: http://www.slideshare.net/NickBelhomme/zend-framework-form-mastering-decorators

Also regarding your code, the "HtmlTag" decorator is being applied so you can try and set that, also you can try and clear the default
decorators.

The default decorators on an element are:

• ViewHelper
• Errors
• Description (only renders if a description is set)
• HtmlTag
• Label

Try $element->removeDecorator('HtmlTag ');

Thanks
Daniel

2009/9/9 Jayawi <[hidden email]>


Hi there~

I'm relatively new to ZF but have enjoyed using it so far. The main issue
I've had with ZF is with it's Form and Decorator aspects. After going
through God knows how many articles/blogs/posts and what not, I thought I
finally had a grasp of it. Things were working okay.

I created a standard set of decorators (for Elements, Buttons and Forms)
based on an example I saw. Recently however, I realised that I needed to add
in some File Input fields into one of the forms. None of the above
decorators worked with it. At which point, I decided to use ViewScripts on
all the forms since it provides greater room to stylise/organise the form.

The code I'm currently using, looks something like the following:

site/application/forms/RegisterForm.php
class ProjectStartContactPersonForm extends Gid_Form
{
       public function init ()
       {
               $this->setAction('')
                               ->setMethod('post')
                               ->setAttrib('id','formStartProject')
                               ->setAttrib('enctype', 'multipart/form-data');

               $this->addElement('text', 'textName', array('label' => 'Given Name'));
               $oName = $this->getElement('textName')
                                               ->setRequired(true)
                                               ->setDecorators(array('ViewHelper', 'Errors'));

               $this->addElement('file', 'filePhotograph');
               $oPhotograph = $this->getElement('filePhotograph')
                                               ->setRequired(true);

               $this->addElement('submit', 'submitRegister', array('label' => 'Done'));
               $oContactPersonSubmit = $this->getElement('submitRegister');
               $oContactPersonSubmit->setDecorators(array('ViewHelper', 'Errors'));

               $this->setDecorators(array(array('ViewScript', array('viewScript' =>
'forms/RegisterForm.phtml'))));
       }
}

site/application/views/scripts/forms/RegisterForm.phtml
<div id='iDivRegister'>
       <form action='' method='post'>
               <table>
                       <tr>
                               <td><label for='textName'>Name:</label></td>
                               <td><?php echo $this->element->textName; ?></td>
                       </tr>
                       <tr>
                               <td><label for='filePhotograph'>Photo:</label></td>
                               <td><?php echo $this->element->filePhotograph; ?></td>
                       </tr>
                       <tr>
                               <td></td>
                               <td><?php echo $this->element->submitRegister; ?></td>
                       </tr>
               </table>
       </form>
</div>

From RegisterForm.php I had to change $this->addElement('file',
'filePhotograph', array('label' => 'Photo')); to get it to work. prior to
that, the File Input element was being displayed twice.
Additionally, if ->setDecorators(array('ViewHelper', 'Errors')) was attached
to the File Input object, it would throw the error "Warning: No file
decorator found... unable to render file element in
C:\xampp\xampp\php\PEAR\Zend\Form\Element.php on line 1929".
I honestly can't understand what the issue is or how I'm supposed to resolve
it. All the searching and reading I did lead me to more questions and no
solution. Some of them dealt with the lack of a File Input Class in ZF
(which I believe was a somewhat early release), while others used custom
classes for things which didn't really clarify anything for me.

Currently, the File Input Element is rendered as follows:
<tr>
       <td><label for='filePhotograph'>Photo:</label></td>
       <td>
               <dt id="filePhotograph-label">&nbsp;</dt>
               <dd><input type="file" name="filePhotograph" id="filePhotograph"></dd>
       </td>
</tr>

I would like to get it outside of those dt/dd tags (which suggest the
default ZF Decorators are being applied).
ZF Documentation I find stragely lacking in the various
methods/variables/parameters to use. If anyone knows of a better reference,
it's sure to help a great deal.

I would greatly appreciate any help anyone can provde me on this.
Thanks~
--
View this message in context: http://www.nabble.com/Zend_Form-File-Element---Decorator---Extremely-Confuzzled-tp25365664p25365664.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Form File Element / Decorator - Extremely Confuzzled

Thomas Weidner
In reply to this post by Jayawi
Take a look into the FAQ where the problem, the reason and the solution is
described:
http://framework.zend.com/wiki/display/ZFFAQ/Forms

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "Jayawi" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, September 09, 2009 4:03 PM
Subject: [fw-general] Zend_Form File Element / Decorator - Extremely
Confuzzled


>
> Hi there~
>
> I'm relatively new to ZF but have enjoyed using it so far. The main issue
> I've had with ZF is with it's Form and Decorator aspects. After going
> through God knows how many articles/blogs/posts and what not, I thought I
> finally had a grasp of it. Things were working okay.
>
> I created a standard set of decorators (for Elements, Buttons and Forms)
> based on an example I saw. Recently however, I realised that I needed to
> add
> in some File Input fields into one of the forms. None of the above
> decorators worked with it. At which point, I decided to use ViewScripts on
> all the forms since it provides greater room to stylise/organise the form.
>
> The code I'm currently using, looks something like the following:
>
> site/application/forms/RegisterForm.php
> class ProjectStartContactPersonForm extends Gid_Form
> {
> public function init ()
> {
> $this->setAction('')
> ->setMethod('post')
> ->setAttrib('id','formStartProject')
> ->setAttrib('enctype', 'multipart/form-data');
>
> $this->addElement('text', 'textName', array('label' => 'Given Name'));
> $oName = $this->getElement('textName')
> ->setRequired(true)
> ->setDecorators(array('ViewHelper', 'Errors'));
>
> $this->addElement('file', 'filePhotograph');
> $oPhotograph = $this->getElement('filePhotograph')
> ->setRequired(true);
>
> $this->addElement('submit', 'submitRegister', array('label' => 'Done'));
> $oContactPersonSubmit = $this->getElement('submitRegister');
> $oContactPersonSubmit->setDecorators(array('ViewHelper', 'Errors'));
>
> $this->setDecorators(array(array('ViewScript', array('viewScript' =>
> 'forms/RegisterForm.phtml'))));
> }
> }
>
> site/application/views/scripts/forms/RegisterForm.phtml
> <div id='iDivRegister'>
> <form action='' method='post'>
> <table>
> <tr>
> <td><label for='textName'>Name:</label></td>
> <td><?php echo $this->element->textName; ?></td>
> </tr>
> <tr>
> <td><label for='filePhotograph'>Photo:</label></td>
> <td><?php echo $this->element->filePhotograph; ?></td>
> </tr>
> <tr>
> <td></td>
> <td><?php echo $this->element->submitRegister; ?></td>
> </tr>
> </table>
> </form>
> </div>
>
>>From RegisterForm.php I had to change $this->addElement('file',
> 'filePhotograph', array('label' => 'Photo')); to get it to work. prior to
> that, the File Input element was being displayed twice.
> Additionally, if ->setDecorators(array('ViewHelper', 'Errors')) was
> attached
> to the File Input object, it would throw the error "Warning: No file
> decorator found... unable to render file element in
> C:\xampp\xampp\php\PEAR\Zend\Form\Element.php on line 1929".
> I honestly can't understand what the issue is or how I'm supposed to
> resolve
> it. All the searching and reading I did lead me to more questions and no
> solution. Some of them dealt with the lack of a File Input Class in ZF
> (which I believe was a somewhat early release), while others used custom
> classes for things which didn't really clarify anything for me.
>
> Currently, the File Input Element is rendered as follows:
> <tr>
> <td><label for='filePhotograph'>Photo:</label></td>
> <td>
> <dt id="filePhotograph-label">&nbsp;</dt>
> <dd><input type="file" name="filePhotograph" id="filePhotograph"></dd>
> </td>
> </tr>
>
> I would like to get it outside of those dt/dd tags (which suggest the
> default ZF Decorators are being applied).
> ZF Documentation I find stragely lacking in the various
> methods/variables/parameters to use. If anyone knows of a better
> reference,
> it's sure to help a great deal.
>
> I would greatly appreciate any help anyone can provde me on this.
> Thanks~
> --
> View this message in context:
> http://www.nabble.com/Zend_Form-File-Element---Decorator---Extremely-Confuzzled-tp25365664p25365664.html
> Sent from the Zend Framework mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend_Form File Element / Decorator - Extremely Confuzzled

Jayawi
Thanks heaps Daniel and Thomas.

I had actually visited that particular FAQ page before, but I thought it a dead-end or login-required page when in fact I now realise that it was due to the horrible internet connection that I have here that the FAQ questions failed to render as a link.

In any case, the FAQ cleared up the confusion I had on the file element. At the moment, going through the slides to see what else I can learn.

Thanks again! :)
Loading...