ZF-7394: Zend_Filter_Input disregards field 'messages' meta-command
Description
Zend_Filter_Input disregards custom error messages passed to it via the 'messages' meta-command. This has been working previously but has been broken since the 1.8 ver. release.
For example, the following validators array:
$validators = array(
'name' => array('NotEmpty','messages' => 'Please enter your name'),
'subject' => array('NotEmpty','messages' => 'Please enter a subject'),
'email' => array('EmailAddress','messages' => 'Please enter a valid Email address'),
'content' => array('NotEmpty','messages' => 'Please enter message contents')
);
Returns the following message stack:
array(5) { ["name"] => array(1) { ["isEmpty"] => string(48) "You must give a non-empty value for field 'name'" } ["subject"] => array(1) { ["isEmpty"] => string(51) "You must give a non-empty value for field 'subject'" } ["content"] => array(1) { ["isEmpty"] => string(51) "You must give a non-empty value for field 'content'" } ["email"] => array(1) { [0] => string(24) "You must give a non-empty value for field 'content''" } }
Comments
Posted by Oleg Luchenko (newatol) on 2009-07-28T01:29:29.000+0000
I confirmed this bug. I have same problem with default error messages. In v.1.7.8 all work's fine.
Posted by Julien Ricard (jarnix) on 2009-08-13T09:39:19.000+0000
This bug occurs only with the "NotEmpty" validator. Other seem to work fine.
Posted by David Mintz (davidmintz) on 2009-08-26T12:16:12.000+0000
@Julien: that's not quite my experience. Consider:
$validators = array( 'email' => array( 'NotEmpty', 'EmailAddress', new Zend_Validate_Regex('/.+nys[dp].uscourts.gov$/i'), 'messages'=>array( 'Email is required', 'Email address is malformed', 'Email domain must be either nysd.uscourts.gov or nysp.uscourts.gov'), 'breakChainOnFailure'=>true,
); $input = new Zend_Filter_Input(null,$validators, array( 'email'=>'barf' ) );
if (! $input->isValid()) { print_r($input->getMessages()); }
outputs the default error message instead of the one I (try to) pass in:
( [email] => Array ( [emailAddressInvalidFormat] => 'barf' is not a valid email address in the basic format local-part@hostname )
)
Posted by Thomas Weidner (thomas) on 2009-08-26T12:27:10.000+0000
@David: You don't use the same notation as Eran... Your problem is different than Eran's.
Posted by David Mintz (davidmintz) on 2009-08-26T12:54:53.000+0000
I don't quite understand why it would matter. It looks like my general problem is "it doesn't work," i.e., can't get Zend_Filter_Input to let me override the default error messages when there's more than one rule on a field. In any case, is my issue something already in the tracker or should I file one? And... do you know if there are any plans to address this issue and/or mine?
Posted by Thomas Weidner (thomas) on 2009-08-26T13:11:56.000+0000
*) When something is different coded than also the issue is different *) That it does not work is not true... using another notation there is no problem at all *) There is already another issue for your notation... a simple search would have shown you this *) As you have seen I took over this issue 6 days ago *) I can not solve 80 issues at the same time so please be patient as already mentioned several times... one after the oher will be solved
Posted by David Mintz (davidmintz) on 2009-08-27T06:33:21.000+0000
*) Reasonable minds may disagree, but I would respectfully submit that when code that conforms to the documented API runs faultlessly in one version of the ZF but generates undesired output in a subsequent version, it can fairly be said that something "doesn't work," and *) I searched in good faith for the issue, with negative results, perhaps because *) your understanding of the issues greatly exceeds my own, which is why you're a contributor and I, a mere consumer, who *) failed to notice you took on the issue so recently, and who, in any event, suggests that you *) please relax and accept my sincere gratitude for your exertions.
Posted by Thomas Weidner (thomas) on 2009-08-27T07:17:22.000+0000
@David: LOL
Let's say: I will solve them soon, ok ?
Your issue is related to ZF-7034 (using one element with multiple validators and messages). Internally I have fixed it already so there is a solution for it soon.
This issue (using multiple elements with one validator and message) could be fixed but I can only verify when I've finished the other one.
When all is ok, then there is a solution within one day. Does this sound good to you ? ;-)
Posted by Thomas Weidner (thomas) on 2009-08-27T10:40:16.000+0000
Fixed with r17845.
And sorry that I was wrong... not one day but only some hours :-)