开发者

Displaying Zend Subform Errors in parent Zend Form

开发者 https://www.devze.com 2023-04-01 14:44 出处:网络
I am aware that form errors can be set to render at the top of the form using decorator code such as:

I am aware that form errors can be set to render at the top of the form using decorator code such as:

$form->setDecorators(array(
                       array('FormElements'),
                       array('FormErrors'),

However, I have su开发者_如何学Gobforms within my (parent) form and I need to render the subforms errors - aggregated and rendered at the top of the parent form. How can this be achieved please? Thanks.


I am a bit new to Zend but I have a similar implementation that acheives this. Although I also have extra code in here that makes the errors display in a custom manner and also puts the subforms into seperate divs.

The important parts to notice are the facts that the errors are turned off on both forms by not specifying the decorator FormErrors and then creating a new errors decorator on the parent form.

On my main form I've added a FormErrors decorator such as this:

$form->setDecorators(array(
    new Zend_Form_Decorator_FormErrors(array(
      'ignoreSubForms'=>false,
      'markupElementLabelStart'=> '<p>',
      'markupElementLabelEnd'=> '</p>',
      'markupListStart'=>'<div class="formErrors">',
      'markupListEnd' => '</div>',
      'markupListItemStart'=>'<div>',
      'markupListItemEnd'=>'</div>'
   )),
   'FormElements'
));

Then on the subform you turn off the form errors

$subForm->setDecorators(array(
   'FormElements',
   array(
      array('data' => 'HtmlTag'),
      array('tag' => 'div', 'class' => 'formRow')
   )
));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号