Zend Form Decorators

23 Oct

Sorry this blog is deprecated.

“You can read This article here”. http://zendgeek.blogspot.com/2009/07/zend-form-decorators.html

About these ads

14 Responses to “Zend Form Decorators”

  1. Ahsan Shahzad October 27, 2008 at 6:28 am #

    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 :)

  2. Asim Zeeshan November 10, 2008 at 3:47 pm #

    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?

  3. Faheem Abbas November 11, 2008 at 5:08 am #

    your hidden filed by default appear like

    dt> /dt>
    dd>
    input type=”hidden” name=”id” value=”” id=”id”>/dd>

    and you want it like this, I think
    input type=”hidden” name=”id” value=”” id=”id”>
    if you want this. then write

    $id->setDecorators(array(
    'viewHelper',
    'Errors',
    array('HtmlTag',array('tag'=>'b'))
    ));

    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.

    $id->removeDecorator(‘DtDdWrapper’);

  4. Ilyas Iqbal November 11, 2008 at 12:14 pm #

    Simply Awesome!
    It really helped me alot, keep it up!

  5. Ilyas Iqbal November 11, 2008 at 2:38 pm #

    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!

  6. Faheem Abbas November 12, 2008 at 8:39 am #

    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.

  7. Developer December 4, 2008 at 3:34 pm #

    Great Work :)

  8. zend dev May 20, 2009 at 12:58 pm #

    Great Article
    very helpful indeed

  9. zend dev May 26, 2009 at 12:04 pm #

    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?

  10. Faheem Abbas May 26, 2009 at 12:19 pm #

    If you want to group form elements, read this.

    http://zendguru.wordpress.com/2008/11/03/zend-form-display-groups-and-decorators-with-example/

  11. Mastertikaf June 10, 2009 at 7:03 am #

    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.

  12. Faheem Abbas June 10, 2009 at 8:11 am #

    “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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 33 other followers

%d bloggers like this: