views:

351

answers:

2

I’m using Zend_Filter_Input to validate form data and want to customize the error messages, if a user does not enter a value. It is important that each field gets a different error message.

With Zend Framework 1.8.0 I used the following array for the “validator” parameter of Zend_Filter_Input:

$validators = array(
 'salutation' => array(
  new Zend_Validate_NotEmpty(),
  Zend_Filter_Input::MESSAGES => array(
   Zend_Validate_NotEmpty::IS_EMPTY => "Please enter a salutation"
  )
 ),
 /* ... */
);

Since I’ve upgraded to ZF 1.8.4, I always get the default message for empty fields (“You must give a non-empty value for field '%field%'”). Obviously Zend_Filter_Input does not call the Zend_Validate_NotEmpty validator anymore, if the field is empty.

Is there a way to change this behavior or another way to get customized “empty” messages for each field?

A: 

It seems that Zend_Filter_Input changed its behaviour when handling empty fields. Empty fields are never processed by rule validators. If a field is empty and allowEmpty is set to true, none of your validators are used. If the field is empty and allowEmpty is set to false, then the default message for empty values is set. Currently there is no way to customize this message for a specific field.

Flo
With Zend Framework 1.8.4 I still get the default message.
eisbernd
Do you get the default message for a missing field or the default message of the NotEmpty-Validator?
Flo
I changed the answer after some research on the topic.
Flo
A: 

The behavior has not changed. This is a bug (http://framework.zend.com/issues/browse/ZF-7394)

Julien
Fixed in 1.9.3.
eisbernd