The only way I have found to get around the misbehaving notEmpty message
template found in validators like Digits and Alnum is to manually set it.  

Surely there must be another way, with the templates in options not working
for me, I have to manually set every notEmpty message which adds quite a few
lines on a complex form.  Setting options for the notEmpty messages isn't
working, have I missed something?

Looking forward to a reply from somone :)
The code below works, but shouldn't the 'notEmptyMessage' template have
picked up on the notEmpty message from the digits validator and replaced it?

Code:

$options = array(
    'notEmptyMessage' => "A non-empty value is required for field
'%field%'",
    'missingMessage' => "'%field%' is missing",
    'presence' => 'required',
    'breakChainOnFailure'=>true,        
    'allowEmpty' => false,
);

$validators = array(
      'month' => array(
        'Digits',        
        array('Between', array(1, 12)),
        'messages' => array(            
            array( Zend_Validate_Digits::STRING_EMPTY => "A month value is
required" ), // WORKS, but without this I just get the default not empty
message from the digits validator!            
            'Month must be between 1 and 12'        
        )
       )
    );
        
$input = new Zend_Filter_Input($filters, $validators, $_POST, $options);
        




fugazied wrote:
> 
> 
> I know its bad discussion etiquette, but does anyone have a possible  
> solution to my problem below?  I have tried it with 1.5 RC 1 and still 
> have the same issue.
> 
> fugazied wrote:
>> I am having some issues with the custom messaging and Zend Input Filter. 
>> Probably something obvious I am missing, but a search couldn't help me
>> find
>> a solution.  Some Code:
>>
>> // ------------------------------------
>> $validators = array(
>>     'email' => array('EmailAddress', 'presence'=>'required',
>> ,'allowEmpty'=>false ),
>>     'month' => array('Digits', 'presence'=>'required',
>> ,'allowEmpty'=>false,
>> array('Between', 1, 10) )    
>> );
>>
>> $options = array(
>>     'missingMessage' => "Field '%field%' is required",    
>>     'notEmptyMessage' => "A non-empty value is required for field
>> '%field%'"
>> );
>>  
>> $input = new Zend_Filter_Input(null, $validators);
>> $input->setOptions($options);
>> $input->setData($_POST);
>>
>> if ($input->hasInvalid() || $input->hasMissing()) {
>>   $invalidFields = $input->getInvalid();
>>   Zend_Debug::dump($invalidFields);
>>
>> /*
>> Produces - 
>> array(2) {
>>   ["email"] => array(1) {
>>     ["emailAddressInvalid"] => string(71) "'' is not a valid email
>> address
>> in the basic format [EMAIL PROTECTED]"
>>   }
>>   ["month"] => array(2) {
>>     ["stringEmpty"] => string(21) "'' is an empty string"
>>     ["notBetween"] => string(43) "'' is not between '1' and '10',
>> inclusively"
>>   }
>> }
>> */
>> }
>> // ------------------------------------
>>
>> I was under the impression that my custom messages would replace the " ''
>> is
>> an empty string ".
>> And to avoid the other error messages appearing, display empty ' ' field
>> values I need to chain the validators correct?
>>
>> Thanks!
>>
>>
>>   
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Zend_Filter_Input-and-messages-tp15782618s16154p15921984.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to