Issues

ZF-2453: Behaviour of Zend_Validate_Input messages is not intuitive

Description

Get error Zend_Validate_Exception: No message template exists for key '' when attempting the intuitive approach:

example:


$validators = array(
    'month' => array(
        'alpha',
        'messages' => 'A month must consist only of letters'
    ),
 'year' => array(
        'digits',
        'messages' => 'A year must consist only of numbers'
    )
);

Closer reading of the docs suggests that the following works:

example:


$validators = array(
    'month' => array(
        'alpha'
    ),
 'year' => array(
        'digits'
    ),
 'messages'  => array ( 
         1  =>  'A month must consist only of letters',
         2  =>  'A year must consist only of numbers' 
     )
);

Also, if this interpretation is correct what approach should one adopt if there is a form field called 'messages'.

Thanks, Ian Lewis

Comments

Please evaluate and categorize/assign as necessary.

This issue is also an issue of Zend_Filter_Input as far as i understood it. Recategorized.

This is more a problem of the bad API of complex Zend_Filter_Input objects.

The solution to this problem is more of a documentation issue (of the bad API). Changes are only possible for 2.0

reassigning, matthew ideas?

I just tested this...

Actually both approaches are usable. Within the testbed the following is checked and works:


        $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')
        );

Seems to be fixed with one of the previous commits. Therefor closing this issue as fixed with the next minor release.