Re: [fw-general] Zend_Filter_Input and messages

2008-03-09 Thread fugazied


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.



Re: [fw-general] Zend_Filter_Input and messages

2008-03-09 Thread Lepidosteus
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 ?

-- 
Vianney Devreese - Lepidosteus
http://lepidosteus.com


Re: [fw-general] Zend_Filter_Input and messages

2008-03-09 Thread Paul Fitzpatrick


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

2008-03-06 Thread Paul Fitzpatrick


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!


  




Re: [fw-general] Zend_Filter_Input custom messages walked on...

2007-08-27 Thread Drew Bertola
Mmm.  I figured out the problem was just confusion between the meaning
of missingMessage and notEmptyMessage.

--
Drew

Drew Bertola wrote:
 Hi,
 
 I'm trying to figure out why I can't set custom messages in
 Zend_Filter_Input.  Is this a known bug?  I've searched around by
 haven't found anything.
 
 Then again, it could be me.  It's happened once or twice before ;^)
 
 If I do something like this:
 
 ?php
 
 ...
 
 $filters= array(name = array(StringTrim, StripTags));
 $validators = array(name = array(presence = required));
 $options = array(missingMessage = %field% is required.);
 
 $input = new Zend_Filter_Input($filters,
$validators,
$data,
$options);
 
 if ( $input-hasInvalid() )
 {
   $messages = $input-getMessages();
 }
 
 Zend_Debug::dump($messages);
 
 ...
 
 When I have an empty name in $data, I see the default missingMessage,
 rather than my custom message passed in $options.  I think the problem
 is actually in Zend_Validate, but I haven't tracked it down that far.
 Any ideas?
 

-- 
Drew Bertola

-
*   PHP/LAMP Consultant, ZCE-1000   *
*   *
*   Tel: 408-966-6671   *
*   *
*   current resume: *
*   http://drewb.com/resume.pdf *
-