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 1116137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:15:30+00:00 2026-05-17T03:15:30+00:00

I’ve set a validator for the email so it can’t be empty. This is

  • 0

I’ve set a validator for the email so it can’t be empty.

This is the markup of the usual form that zend_form generates:

<dt id="email-label"><label class="required" for="email">Email</label></dt>
<dd id="email-element">
   <input type="text" value="" id="email" name="email">
</dd>

When validation fails, zend_form adds a new ul class="errors" inside the dd

<dt id="email-label"><label class="required" for="email">Email</label></dt>
<dd id="email-element">
   <input type="text" value="" id="email" name="email">
   <ul class="errors">
      <li>Value is required and can't be empty</li>
   </ul>
</dd>

How can I change this default behavior slightly so that the entire dt dd gets wrapped in a single p or something that I can add an error class to? My guess is that I need to specify to zend_form how to behave when an element has errors.

  • 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-17T03:15:30+00:00Added an answer on May 17, 2026 at 3:15 am

    You can create your own decorator to do that, something simple like this::

    class My_Decorator_ElementWrapper extends Zend_Form_Decorator_Abstract
    {
        public function render($content)
        {
            $class = 'form-element';
            $errors = $this->getElement()->getMessages();
            if (!empty($errors))
                $errors .= ' has-errors';
            return '<div class="'.$class.'">' . $content . '</div>';
        }
    }
    

    Now you can just register this decorator for the element:

    $element->addPrefixPath('My_Decorator', 'My/Decorator/', 'decorator');
    $element->addDecorator('ElementWrapper');
    

    You can also register the prefix path for all elements at the same time by using $form->addElementPrefixPath() instead.

    If you want to add this decorator (and the prefix path) automatically for all elements, I suggest you extend each element the Zend’s corresponding one (eg. make My_Form_Element_Text that extends Zend_Form_Element_Text), and then add the prefix path in the init function, and override loadDefaultDecorators() method to add the ElementWrapper at the end of the decorator chain. For example, this is how loadDefaultDecorators() looks for Zend_Form_Element_Text:

    public function loadDefaultDecorators()
    {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return $this;
        }
    
        $decorators = $this->getDecorators();
        if (empty($decorators)) {
            $this->addDecorator('ViewHelper')
                ->addDecorator('Errors')
                ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
                ->addDecorator('HtmlTag', array('tag' => 'dd',
                                                'id'  => $this->getName() . '-element'))
                ->addDecorator('Label', array('tag' => 'dt'));
        }
        return $this;
    }
    

    You’d just add a ->addDecorator('ElementWrapper') at the end of the chain. So to show a concrete example of My_Form_Element_Text:

    class My_Form_Element_Text extends Zend_Form_Element_Text
    {
        public function init()
        {
            $this->addPrefixPath('My_Decorator', 'My/Decorator/', 'decorator');
        }
    
        public function loadDefaultDecorators()
        {
            if ($this->loadDefaultDecoratorsIsDisabled()) {
                return $this;
            }
    
            $decorators = $this->getDecorators();
            if (empty($decorators)) {
                $this->addDecorator('ViewHelper')
                    ->addDecorator('Errors')
                    ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
                    ->addDecorator('HtmlTag', array('tag' => 'dd',
                                                    'id'  => $this->getName() . '-element'))
                    ->addDecorator('Label', array('tag' => 'dt'))
                    ->addDecorator('ElementWrapper');
            }
            return $this;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
Does anyone know how can I replace this 2 symbol below from the string
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.