I figured out the problem. You have to set required to false and allow_empty to true in order to set a custom message on a NotEmpty validator. The problem is that I want the input to be required and I want a custom message. Currently you can have one or the other but not both. I filed an issue for this in the issue tracker.
Mark -- Have fun or die trying - but try not to actually die. On Saturday, June 30, 2012 at 9:49 PM, mark.wright [via Zend Framework Community] wrote: > If I follow your example exactly it still uses the default message. However, > if I follow your example with the StringLength validator things get > interesting. I tried using this as the validators array: > > 'validators' => array( > array( > 'name' => 'string_length', > 'options' => array( > 'min' => 1, > 'max' => 50, > 'encoding' => 'utf-8', > 'messages' => array( > StringLength::TOO_LONG => 'First name can not be > more than 50 characters long.', > StringLength::TOO_SHORT => 'First name is > required.', > ) > > ), > ), > ), > > If I pass in a string more than 50 chars long I get the custom too_long > message but if I pass in an empty string I get a default isEmpty message even > though no isEmpty validator is set. If I change the min to 2 and pass in a > single char string I get the expected custom too_short message. So it seems > that the input filter is doing a NotEmpty validation on every input. I tried > setting required to false and it made no difference. Is there any way around > this? > > > > Mark > > > macest wrote > > $inputFilter->add( array( 'name' => 'foo', 'validators' => array( array( > > 'name' => 'NotEmpty', 'options' => array( 'messages' => array( > > \Zend\Validator\NotEmpty::IS_EMPTY => 'Please enter a value for "foo".', ), > > ), ), ), ) ); > > > > > > > > If you reply to this email, your message will be added to the discussion > below: > http://zend-framework-community.634137.n4.nabble.com/zf2-custom-messages-in-input-filter-tp4655498p4655565.html > > To unsubscribe from Zend Framework Community, click here > (http://zend-framework-community.634137.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=634137&code=c3Bhcmt5bWVpc3RlckBnbWFpbC5jb218NjM0MTM3fC0xNTE2Mzk4Mjk2). > NAML > (http://zend-framework-community.634137.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml) > -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/zf2-custom-messages-in-input-filter-tp4655498p4655575.html Sent from the Zend Framework mailing list archive at Nabble.com.
