You are not logged in.
One of the pain points for folks who are starting to work with the Zend Framework is the Decorating functionality found in the depths of Zend_Form. I've witnessed countless instances when a developer becomes excited by Zend_Form's easy-to-implement form validation and creation, only to become frustrated by countless hours of fighting with Zend_Form_Decorators. This video is a humble attempt on my part to walk through how Zend_Form Decorators work and how you can reason your way through a desire result. I couldn't have gotten my own head around this implementation of the decorator pattern without Matthew Weier O'Phinney's excellent posts and his original devzone article.
I'll show you a bit about how Zend_Form_Decorators are constructed and how to take the default zend_form layout and transform it into a table.
Grab a copy of the project or browse the repository.
Offline
Wow what a nice video! I much prefer this style then the other ones. Personnaly I dont really need help coding little functionnality in my websites but a indepth look at a ZF element like form decorators is really great and saves me the hassle of having to discover it all by myself.
I'll try to implement this. As of now I use forms and ViewScript to display custom forms. It works well but it doubles the code I have to write.
Keep up the good work!
Offline
Finally someone explain in good old english how the damn Decorators works.
The Zend_Form_Decorators are a mixed of the Decorator and Strategy Patterns, I believe, the concept is simple but it is hard to get.
Jon you're the man.
Thanks
Offline
Jon,
Thanks for this informative video. I cannot wait to see your video about custom decorators.
Offline
Thanks for your useful videos.
i want to know how can i decorate error message?
and may you create a tutorial about implement WYSIWYG editors on zend framework?
Last edited by ulduz114 (2010-02-25 10:34:39)
Offline
just include the "FormErrors" decorator! ![]()
Offline
I faced some problems when I used the type 'file'.
At first showed the error:
"Warning: Exception caught by form: No file found ... decorator unable to render file element"
Simply place the decorator 'File'.
But from now shows another error:
Warning: Exception caught by form: Method getMaxFileSize does not exist
And I stopped here ever since. I tried several configurations:
$ maxfilesize = new Zend_Form_Element_Hidden ( 'form element');
$ maxfilesize-> setValue (204800);
$ photo = new Zend_Form_Element_File ( 'photo');
$ photo-> setLabel ( 'Photo')
-> setValidators (array (
array ( 'Count', false, 1),
array ( 'Size', false, 204800),
array ( 'Extension', false, 'jpg, gif, png'),
array ( 'NotEmpty', true)
))
/ / -> setMaxFileSize (20000)
-> setRequired (true);
But still without success. Is there opportunity to help with this?
Thank you.
Att
Offline
I believe I discovered the flaw but falls in further questions. According to this link:
http://framework.zend.com/wiki/display/ZFFAQ/Forms
It needs another decorator, following the example shown in zendcast 47 I can not put the two (File and viewhelp) decorators together. Does anyone have any suggestions?
Thank you.
Offline
just include the "FormErrors" decorator!
That's excactly what I tried to do. 'Errors' shouldn't be any different than 'Label'. So this is what I did:
$this->setElementDecorators(array(
‘ViewHelper ‘,
array( 'Errors',
array( 'tag' => 'td', 'placement' => 'APPEND' ),
array(
array( ‘data‘ => ‘HtmlTag‘),
array( ‘tag‘ => ‘td‘,‘class‘ => ‘element‘ )
),
array( ‘Label‘,
array( ‘tag‘ => ‘td‘ )
),
array(
array(‘row‘ => ‘HtmlTag‘),
array( ‘tag‘ => ‘tr‘,‘class‘ => ‘row-element‘ )
)
) );In my head, it should be no different adding a td tag to the errors than to the label. But my head does not always compute with Zend and in this case, what this does is adding an attribute to the ul element called td.
So where should I manipulate the Error decorator? I want it to render itself the same ( ul -> li ), but I want it to have an additional td around the ul.
Offline
if I wanted to insert errors without 'ul' and 'li'
Offline
Ok. I did't get something.
in my source i have
<label...
<input ...
<label ...
<input...
so when when i decorate, i wrap and wrap and wrap..
but what if i want my labels to be on a row and my elements to be on another row so it will be like
<tr><td><label></label></td><td><label></label></td></tr>
<tr><td><input/></td><td><input/><td></tr>
how is this going to happen? I can't figure it out :S
Last edited by SocialEvil (2010-06-30 06:53:31)
Offline
Hi there,
I've a question about thr "FormErrors" décorator, so :
$this->setDecorators(array(
array('FormErrors', array()),
'FormElements',
array('HtmlTag', array('tag' => 'table', 'class'=> 'table_edit_news')),
'Form'
));This code generate the html, accordding the ZF website :
<ul class="form-errors>
<li><b>[element label or name]</b>
<ul>
<li>[error message]</li>
<li>[error message]</li>
</ul>
</li>
</ul>How can I remove the [element label or name] line : <b>[element label or name]</b>
I know I can modify "markupElementLabelStart " and "markupElementLabelEnd " but not remove. In fact, I want only the list of errors, in the "FormErrors" decorator.
Any idea ?
Regards,
Fabrice
Last edited by __fabrice (2010-09-14 20:35:59)
Offline
Hello,
I am trying to create a printable representations of a completed form.
So, instead of a input field, I have added a form element called Note
class SF_Form_Element_Note extends Zend_Form_Element_Xhtml
{
public $helper = ‘formNote’;
}
My problem is that I am trying to place a span tag around the data text
my decorator for this field is as follows:
public function printDecorators ($id)
{
return array(
array(‘ViewHelper’, array(array(‘data’ => ‘HtmlTag’), array(‘tag’ =>’span’)),
array(array(‘data2′ => ‘HtmlTag’), array(‘tag’ =>’span’, ‘id’ => $id))),
array(‘Label’, array(‘tag’ =>’span’)),
array(‘Errors’),
array(‘HtmlTag’)
);
I get
<div>
</div><span id="printtab-first_name-label"><label for="printtab-first_name" class="optional">First Name</label></span>
Jeffery</div>
<div><span id="printtab-last_name-label"><label for="printtab-last_name" class="optional">Last Name</label></span>
Shipman</div>
</div>
what I would like is
<div>
</div><span id="printtab-first_name-label"><label for="printtab-first_name" class="optional">First Name</label></span>
<span id="first">Jeffery</span></div>
<div><span id="printtab-last_name-label"><label for="printtab-last_name" class="optional">Last Name</label></span>
<span id="last">Shipman</span></div>
</div>
Offline