Zend Framework

Add public accessors for errors and messages for elements

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.6.0
  • Component/s: Zend_Form
  • Labels:
    None
  • Fix Version Priority:
    Must Have

Description

I didn't want to add a custom validators and decided to override my form's isValid() instead. Doing my custom logic there was straightforward, except that I couldn't set the errors on my elements as they are managed internally by Zend_Form_Element with no public accessors.

I propose that we add public accessors for errors and messages. It makes sense regardless of the use case I demonstrated.

Activity

Hide
Andries Seutens added a comment -

Currently, you always have to write your own validator, in order to get an error in the stack. I also think it'd be usefull to have a method to push your own custom errors into the error stack on a per element basis:

$myElement->addError('key', 'error message');

It would also be convenient to be able to do this on form level, where the input would be an array:

$form->addErrors(Array $myCustomErrors);

vote +1

Show
Andries Seutens added a comment - Currently, you always have to write your own validator, in order to get an error in the stack. I also think it'd be usefull to have a method to push your own custom errors into the error stack on a per element basis:
$myElement->addError('key', 'error message');
It would also be convenient to be able to do this on form level, where the input would be an array:
$form->addErrors(Array $myCustomErrors);
vote +1
Hide
Wil Sinclair added a comment -

Please evaluate and categorize as necessary.

Show
Wil Sinclair added a comment - Please evaluate and categorize as necessary.
Hide
Steven Reed added a comment -

Can this please include hasErrors()?

An example use case would be determining whether or not to add an 'error' class to a tag when using the ViewScript decorator:

<div class="row <? if ($this->element->hasErrors()): ?>error<? endif ?>">
    // label/element output here
</div>
Show
Steven Reed added a comment - Can this please include hasErrors()? An example use case would be determining whether or not to add an 'error' class to a tag when using the ViewScript decorator:
<div class="row <? if ($this->element->hasErrors()): ?>error<? endif ?>">
    // label/element output here
</div>
Hide
Matthew Weier O'Phinney added a comment -

New functionality complete as of r10162.

Show
Matthew Weier O'Phinney added a comment - New functionality complete as of r10162.
Hide
Wil Sinclair added a comment -

Updating for the 1.6.0 release.

Show
Wil Sinclair added a comment - Updating for the 1.6.0 release.

People

Vote (8)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
20m
Original Estimate - 20 minutes
Remaining:
20m
Remaining Estimate - 20 minutes
Logged:
Not Specified
Time Spent - Not Specified