Remove Form Decorators From view file in Zend Framework

If you want complete customization of the zend form, it can be done through the Decorators by using addDisplayGroup() method. But for new users it is little bit difficult and need to write lots of code. You can do this in view script.In view script I had remove all the decoration of the default zend form by using this code:

$form = $this->form;
foreach ($form->getElements() as $element)
{
    $element->removeDecorator('DtDdWrapper')
            ->removeDecorator('HtmlTag')
            ->removeDecorator('Label')
            ->removeDecorator('Errors');
}

Removed all the decoration of the form.
To show the errors before the forms:

foreach ($this->form->getMessages() as $elemName => $messages)
{
    foreach ($messages as $message)
    {
        $label = $form->getElement($elemName)->getLabel();
        echo $this->escape($label . ':' . $message);
    }
}

The generate the form in the following way and then organize your form elements as you want.

<form method="<?php echo $form->getMethod() ?>" action="<?php echo $form->getAction() ?>">
          <?php
          echo $form->categoryName;
          echo'<br />';
          echo $form->groupName;
          echo'<br />';
          echo $form->Submit;
          echo'<br />';
          echo $form->Clear;
          ?>          
</form>
Advertisements

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