Zend Framework

Custom error message from Zend_Validate_NotEmpty not considered when using it along with Zend_Filter_Input

Details

Description

Given the following code

require_once 'Zend/Filter/Input.php';
        
        require_once 'Zend/Validate/NotEmpty.php';
        
        
        $notEmpty = new Zend_Validate_NotEmpty();
        $notEmpty->setMessage("\"key\" may not be empty", Zend_Validate_NotEmpty::IS_EMPTY);
        
        $filter = New Zend_Filter_Input(array(), array(
            'key' => array($notEmpty)
        ), array('key' => ""));
    
        var_dump($filter->getInvalid());

I expect the following result:

array
  'key' => 
    array
      'isEmpty' => string 'You must give a non-empty value for field 'key''

However, I'm getting the following result

array
  'key' => 
    array
      'isEmpty' => string '"key" may not be empty'

which means that there is no way to actually use the NotEmpty Validator along with a custom error message, since some funny Zend_Filter_Input implementation preceeds my validator configuration.

Activity

Hide
Thorsten Suckow-Homberg added a comment -

uhm... what's wrong with the monospace wiki syntax?

Show
Thorsten Suckow-Homberg added a comment - uhm... what's wrong with the monospace wiki syntax?
Hide
Thorsten Suckow-Homberg added a comment -

nvm

Show
Thorsten Suckow-Homberg added a comment - nvm
Hide
Bart McLeod added a comment -

Today I created a unit test that proves this error exists. I had previously discovered the error in a more informal way. The bad news is, that other validators are equally affected by this issue, not just the 'NotEmpty' validator.

I will try to fix this.

Show
Bart McLeod added a comment - Today I created a unit test that proves this error exists. I had previously discovered the error in a more informal way. The bad news is, that other validators are equally affected by this issue, not just the 'NotEmpty' validator. I will try to fix this.
Hide
Bart McLeod added a comment -

Added patches that resolve the issue.

I will leave the patches here for a few days for community review.

I will also assign it to Thomas hoping that he will find the time to evaluate them before I commit them.

Show
Bart McLeod added a comment - Added patches that resolve the issue. I will leave the patches here for a few days for community review. I will also assign it to Thomas hoping that he will find the time to evaluate them before I commit them.
Hide
Bart McLeod added a comment -

Changed to patch and assigned to Thomas.

Show
Bart McLeod added a comment - Changed to patch and assigned to Thomas.
Hide
Thomas Weidner added a comment -

Looks good on the first hand.
Thanks for the fix.
Please add the patch to ZF1 and keep the issue opened for integration into ZF2.

Show
Thomas Weidner added a comment - Looks good on the first hand. Thanks for the fix. Please add the patch to ZF1 and keep the issue opened for integration into ZF2.
Hide
Bart McLeod added a comment -

fix is in svn now

Show
Bart McLeod added a comment - fix is in svn now
Hide
Bart McLeod added a comment -

reopened for integration into ZF2

Show
Bart McLeod added a comment - reopened for integration into ZF2
Hide
Thomas Weidner added a comment -

Added to ZF2 with GH-274
Changed assignee to Bart because it was his patch

Show
Thomas Weidner added a comment - Added to ZF2 with GH-274 Changed assignee to Bart because it was his patch

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: