14 Responses to “Zend Form Decorators”
Trackbacks/Pingbacks
-
-
February 4, 2009
[...] Excellent References: http://framework.zend.com/manual/en/zend.form.standardDecorators.html http://devzone.zend.com/article/3450-Decorators-with-Zend_Form http://zendguru.wordpress.com/2008/10/23/zend-form-decorators/ [...]
-
-
February 4, 2009
[...] http://devzone.zend.com/article/3450-Decorators-with-Zend_Form http://zendguru.wordpress.com/2008/10/23/zend-form-decorators/ Possibly related posts: (automatically generated)Zend Form [...]
Great Article!
thanks for it, i really found it helpful.
I was in search for some practical example and fortunately u provided here, thanks again
Very nice article, but I had a problem implementing it.
Hidden fields are still in definition list, If I add decorators to hidden fields, my CSS will be applied to those TABLE ROWS too.
Any solution?
your hidden filed by default appear like
and you want it like this, I think
input type=”hidden” name=”id” value=”" id=”id”>
if you want this. then write
I am enclosing it in “b” tag so it will appear in form but not in row. you can even place it in “span” tag.
The code below should also work, however In case of hidden fields it is not working as i have checked it here.
Simply Awesome!
It really helped me alot, keep it up!
Hi,
May be there are more than one solutions to accomplish this task, so for that I got another good piece of code which I wanted to share with all of you guys, here I’m putting it:
class My_Form_Registration extends Zend_Form
{
public $elementDecorators = array(
‘ViewHelper’,
‘Errors’,
array(array(‘data’ => ‘HtmlTag’), array(‘tag’ => ‘td’, ‘class’ => ‘element’)),
array(‘Label’, array(‘tag’ => ‘td’),
array(array(‘row’ => ‘HtmlTag’), array(‘tag’ => ‘tr’)),
);
public $buttonDecorators = array(
‘ViewHelper’,
array(array(‘data’ => ‘HtmlTag’), array(‘tag’ => ‘td’, ‘class’ => ‘element’)),
array(array(‘label’ => ‘HtmlTag’), array(‘tag’ => ‘td’, ‘placement’ => ‘prepend’)),
array(array(‘row’ => ‘HtmlTag’), array(‘tag’ => ‘tr’)),
);
public function init()
{
$this->addElement(‘text’, ‘username’, array(
‘decorators’ => $this->elementDecorators,
‘label => ‘Username:’,
);
$this->addElement(‘text’, ‘firstname’, array(
‘decorators’ => $this->elementDecorators,
‘label => ‘First Name:’,
);
$this->addElement(‘text’, ‘lastname’, array(
‘decorators’ => $this->elementDecorators,
‘label => ‘Last Name:’,
);
$this->addElement(‘submit’, ‘save’, array(
‘decorators’ => $this->buttonDecorators,
‘label => ‘Save’,
);
}
public function loadDefaultDecorators()
{
$this->setDecorators(array(
‘FormElements’,
array(‘HtmlTag’, array(‘tag’ => ‘table’)),
‘Form’,
));
}
}
Enjoy!
yes i have applied same technique in my application. however I wrote this post to show how we can use decorators. another post http://zendguru.wordpress.com/2008/11/11/applying-decorators-to-all-elements-of-form-elements-at-once/ is good place to apply decorators to all form elements at once.
Great Work
Great Article
very helpful indeed
hi
when i use decorators,
it places legend in a separate row and all elements that i had grouped i the legend out of the legend in separate rows
why’s this so?
If you want to group form elements, read this.
http://zendguru.wordpress.com/2008/11/03/zend-form-display-groups-and-decorators-with-example/
Hi !
I’m new in the Zend World and this article is very helpfull !
Althougt you said that “We are skipping “ViewHelper”, “Description” and “Errors” for now.” and that I want to now it’s :
Why do we need to put them in the decorators setting declarations ? I don’t find the answer.
Thanks !
Great job.
“viewHelper”: for displaying our form elements in view template.
“Description”: for appending for pre-pending description next to form element.
“Error”: for displaying error messages next to each element, if any.
This is short description bro.