|
In zf1 you could set default messages for validators. You could add a "messages" key to the validators array with an array of messages. That doesn't seem to be working in zf2 and I see nothing about it in the docs. Is this still possible?
Mark -- Have fun or die trying - but try not to actually die. |
|
This post has NOT been accepted by the mailing list yet.
$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".', ), ), ), ), ) ); |
|
This post has NOT been accepted by the mailing list yet.
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
|
|
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:
|
|
This post has NOT been accepted by the mailing list yet.
There is a way to override the default validation applied by the form object.
In the constructor for your form, just add the line: $this->setUseInputFilterDefaults(false); This will prompt the form object not to use the defaults associate with the elements created on form construction. No only the validators you implement on the form explicitly will actually be taken into consideration. |
|
In reply to this post by macest
Hi,
I am included this in Base.php $this->add(array( 'type' => 'Zend\Form\Element\Select', 'name' => 'gender', 'options' => array( 'label' => 'Gender', 'value_options' => array( '1' => 'Select your gender', '2' => 'Female', '3' => 'Male' ), ), 'attributes' => array( 'value' => '1' //set selected to '1' ) )); But output of radio button not coming -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/zf2-custom-messages-in-input-filter-tp4655498p4659220.html Sent from the Zend Framework mailing list archive at Nabble.com. -- List: [hidden email] Info: http://framework.zend.com/archives Unsubscribe: [hidden email] |
| Powered by Nabble | Edit this page |
