Romoving unnecessary dt and dd’s in Zend

5 Nov

Few days back I come across a new problem.

Zend by default wrap some form elements like display groups and form itself in

dt and dd. this disturb the entire page layout.

I tried different ways to change this default behavior. After googling for lot of time I found a simple solution.

just try this

$form->removeDecorator(“DtDdWrapper”);

similarly

$displayGroupName->removeDecorator(‘DtDdWrapper’);

you can remove DtDWrapper’s from all elements using this magic method-removeDecorator(“DtDdWrapper”);

Some time you want to remove label from your form element. so try this one

$element->removeDecorator(“Label”);

that’s it. enjoy.

5 Responses to “Romoving unnecessary dt and dd’s in Zend”

  1. Surt February 5, 2009 at 11:43 am #

    Hi, i was triying to remove all dl dd dt markup on the forms, (i still can’t understand why this markup by default on zend_form).

    Using :

    $this->removeDecorator(‘HtmlTag’);
    $this->removeDecorator(‘DtDdWrapper’);
    $this->groupname->removeDecorator(‘DtDdWrapper’);

    i can remove “dt dd” for the fieldset and the “dl dd dt” for the form, but my elements still have “dd dt” can i remove it from ALL the elements at a time?

    I don’t want to define my own decorator for the elements, i fear to destroy some important features for file inputs, etc.. just want to remove “dd dt” markup.
    Must i remove it from each element?

  2. Faheem Abbas February 6, 2009 at 5:47 am #

    To remove decorators from all form elements, write
    foreach($form->getElements() as $element) {
    $element->removeDecorator(‘DtDdWrapper’);
    $element->removeDecorator(‘Label’);
    }

  3. Surt February 12, 2009 at 6:20 pm #

    Thanx a lot Faheem Abbas, getElements! good one.
    Anyway, removing dtdWrapper on my elements does nothing, i did:

    $element->removeDecorator(‘HtmlTag’)
    ->removeDecorator(‘Label’)
    ->addDecorator(‘Label’);

    removing and adding label to destroy the tag, no way using tag=” or null or false😦

    why in the hell Zend developers are putting a (x)html markup on my programming libraries!😦

  4. heik October 30, 2009 at 3:51 pm #

    “Zend by default wrap some form elements like display groups and form itself in dt and dd. this disturb the entire page layout.”
    –> you mean this stupid “intend-like” movement of input fields!? I had the same problem and solved it as follows:

    – created own decorator called My_Decorator_FormElements extends Zend_Form_Decorator_FormElements
    – just added one method: public function render($content) { return “” . parent::render($content).””; }
    – in Form class: $this->addPrefixPath(‘My_Decorator’, ‘My/decorator’, ‘decorator’);

    -> Zend_Form now uses My Decorator for FormElements:

    The Form wraps the missing “” around the Elements and the intend is gone🙂

    Cheers,
    heik

  5. heik October 30, 2009 at 3:54 pm #

    … oops .. got filtered out -> “The Form wraps the missing dl tags around the Elements and the intend is gone”

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

%d bloggers like this: