Posted by Faheem Abbas on October 23, 2008
Sorry this blog is deprecated.
This entry was posted on October 23, 2008 at 5:30 pm and is filed under Zend Framework.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Ahsan Shahzad said
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
Asim Zeeshan said
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?
Faheem Abbas said
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.
Ilyas Iqbal said
Simply Awesome!
It really helped me alot, keep it up!
Ilyas Iqbal said
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!
Faheem Abbas said
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.
Developer said
Great Work
Zend Framework: Extending Decorators Flexibility (Part 1) « Turboflash’s Blog said
[...] 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/ [...]
Zend Framework: Extending Decorators Flexibility (Part 1) « Turboflash’s Blog said
[...] 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 [...]
zend dev said
Great Article
very helpful indeed
zend dev said
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?
Faheem Abbas said
If you want to group form elements, read this.
http://zendguru.wordpress.com/2008/11/03/zend-form-display-groups-and-decorators-with-example/
Mastertikaf said
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.
Faheem Abbas said
“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.