ZF-3917: Zend_Form_Element::isValid() losing error messages with arrays


If you create an element that represents an array and configure a validator, then isValid() will run the validators on each of the values.

Problem 1: array_merge() is used to concatenate messages and errors If two values have the same error (but a different message), then entries in $messages will be overwritten, since the key (error) is the same.

Problem 2: Information about which of the values caused which message/error is lost, so it's impossible to render the error message next to the individual values.

Background: I ran into this bug(1)/limitation(2) when working on a decorator which would replace ViewHelper and allow rendering of ANY element as an array (with the help of some javascript). For example, you could add a "text" element and set isArray and the decorator would render it as a series of text inputs with the user having an option to remove any of them or add new ones.

Suggestion: Keep errors and messages in a separate array for each of the values, e.g.: array( [0] => array( [errors] => same as now, [messages] => same as now, ), [1] => array( [errors] => same as now, [messages] => same as now, ), )

Then to maintain backwards compatibility and simplicity merge them on the call to getMessages()/getErrors(). Additionaly add methods like getMessagesForValue($index)/getErrorsForValue($index).

Regards, Jaka


Fixed in trunk r22072 and 1.10 release branch. ZF-9788