Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7076961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:21:47+00:00 2026-05-28T06:21:47+00:00

I need to display form-level errors in my forms (errors that do not belong

  • 0

I need to display form-level errors in my forms (errors that do not belong to one field, but to the whole form submission), with this code:

$form->addError($message);

For this to work, I need to add the relevant decorator to my form:

$form->addDecorator('Errors');

Fairly easy. The problem is that applying a new decorator causes all default decorators to be removed, thus forcing me to re-apply all of them:

$form->addDecorator('Errors')
     ->addDecorator('FormElements')
     ->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
     ->addDecorator('Form');

This is some redundant code I have in most of my forms. Is it possible to have the Errors decorator part of the default decorators, by applying some setting?

I could obviously create an abstract Form class to inherit from, but I’m wondering if I’m missing a simpler or more elegant solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:21:48+00:00Added an answer on May 28, 2026 at 6:21 am

    You can override the loadDefaultDecorators method to create a form class that support errors like:

    /**
    * Form with error decorator included by default 
    */
    class ErrorForm extends Zend_Form {
    
       public function loadDefaultDecorators() {
           $this->addDecorator('Errors');
           $decoratorsWithError = $this->getDecorators();
    
           //clearing to let the parent do default business
           $this->clearDecorators();
           parent::loadDefaultDecorators();
    
           //union decorators array so error is first
           $finalDecorators = $decoratorsWithError + $this->getDecorators();
    
           //finally
           $this->setDecorators($finalDecorators);
           return $this;
        }
    
    }
    

    Errors decorator should be the first one to render.
    I think more elegant solution would require Zend_Form refactoring.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to display elapsed time in my application form. I currently do this
I have a need to display a custom form instead of the default inspector
So I am writing a registration form and I need the display name to
I have a requirement wherein I need to display on a User form, a
I'm processing subscription form with jQuery/ajax and need to display results with success function
i am developing one application with map view i need display the weather depends
I need to display additional information, like a tooltip, but it's a lot of
I need to display the checkboxes in tabular form as in attached image. I
I need to display an image in a Django form. My Django form is
I need to display part of the exposed form in my page's sidebar, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.