Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-2008, 10:20 AM
Junior Member
 
Join Date: May 2008
Posts: 2
Default Custom Error Messages using Zend Decorators

I am having two problems with Zend Form and Zend Decorators that are driving me crazy.

I am trying to get this html structure when I get a form error:

<li class="error">
<label class="desc" for="name"> First Name </label>
<div>
<input class="field text half" name="name" type="text" value="" />
</div>
<p class="hint"> Your nickname </p>
<p class="error"> Error Message </p>
</li>

  1. I want to replace the <ul> and <li> elements of the error messages with a <p> element. And then to have it print out an error message at the bottom of the <li>.
  2. I want to add the class "error" to the <li> when it returns an error. I imagine the code will look something like the code below, but I can't figure it out.

if( $form->isValid($formData) ) {
...
} else {
$this->view->message = 'Validation Failed.';
$form->setElementDecorators(...);
}

Thanks so much for any help,
Daniel
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-28-2008, 12:15 PM
Junior Member
 
Join Date: Jul 2008
Posts: 2
Thumbs up how to

You must override your isValid function and manipulate the decorators there, basically you need to manipulate the HtmlTag decorator of the item with error and setOption('class', 'error')

sample:
PHP Code:
     public function isValid($formData) {
          
$isValid parent::isValid($formData);
          if(!
$isValid) {
               
$errors $this->getErrors();
               foreach(
$errors as $fn => $error) {
                    if(empty(
$error)) continue;
                    
$el $this->getElement($fn);
                    
$dec $el->getDecorator('HtmlTag');
                    
$dec->setOption('class''witherrors');
                }
           }
           return 
$isValid;
     } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:38 AM.