Re: [fw-general] Zend_Filter_Input and messages
Hi, The intention is to create a custom message template for missing input values for Zend_Filter_Input. I would hope to set the 'notEmptyMessage' meta attribute in the $options array getting fed to Zend_Filter_Input. I thought the meta attribute would have allowed me to create default messages for every missing input value, but it did not work, I kept receiving default messages from some validators. Some validator types (Digits, Alnum) have a notEmpty validator whose message is used instead of the notEmptyMessage message template I defined in the options array. After a few hours of puzzlement, I checked the bugs affecting Zend_Filter_Input and yes there is a bug report for it. I should have checked the outstanding bugs, something I will remember to do next time because I did spend a chunk of time wondering if I was doing something wrong. The bug: http://framework.zend.com/issues/browse/ZF-1912 The workaround is to set each message type manually, a bit of pain and extra code but the fix in the Zend framework should be coming soon I hope. // Works. $validators = array( 'month' => array( 'Digits', array('Between', array(1, 12)), 'messages' => array( array( Zend_Validate_Digits::STRING_EMPTY => "A month value is required", Zend_Validate_Digits::NOT_DIGITS => "Month must only consist of numbers or letters" ), 'Month must be between 1 and 12' ) ) ); Thanks. Paul Lepidosteus wrote: I did not fully understand what you are trying to achieve here ? Do you try without success to change an error message ? To allow an empty value ? To disallow an empty value ?
Re: [fw-general] Zend_Filter_Input and messages
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!