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

Issue Type: Bug Created: 2008-08-10T05:27:13.000+0000 Last Updated: 2010-05-04T00:29:38.000+0000 Status: Resolved Fix version(s): Reporter: Jaka Jancar (jaka) Assignee: Christian Albrecht (alab) Tags: - Zend_Form

Related issues: - ZF-9467



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


Posted by Christian Albrecht (alab) on 2010-05-04T00:29:36.000+0000

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.