Re: [fw-general] Zend_Form and validation language
Ok ok... Matthew Weier O'Phinney-3 wrote: > > Currently, yes, but I'm considering adding an additional decorator for > field and form hints for the 1.5.0 final release.. > Thanks :) > Yes -- by passing a messages option to the validator when creating the > element and/or validator. > > $element->addValidator( > 'NotEmpty', > false, > array('messages' => array('isEmpty' => 'Alternate message')) > ); > > You can also pull out the validator object and set the messages you > want. > > $element->getValidator('NotEmpty')->setMessage('isEmpty', 'Alternate > message'); > Yes, that's why i asked... ok... > So, there are a variety of ways to do this. However, if you use a > translator object, then the translations will always be used, so the > same translation will be used in all instances of a particular validator. > How about having the fieldname prefixing the messageid in the language csv's ? Some sort of "username.isEmpty;The string username cannot be empty" ? -- View this message in context: http://www.nabble.com/Zend_Form-and-validation-language-tp15248574s16154p15292524.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form and validation language
Two questions now come to my mind : - Is it mandatory to use decorators to place a hint text below fields ? - Is it possible to specify a different error message for the same error in two different fields ? I mean this way (if it's not already possible, this code comes from ALkyD on Z-f.fr), he's got a sub-class Form which inherits of Zend_Form with a method setValidatorMessages(array $messages) : public function setValidatorMessages(array $messages) { $elements = $this->getElements(); $i = 0; foreach ($elements as $el) { $validators = $el->getValidators(); foreach ($validators as $v) { if (is_array($messages[$i])) $v->setMessages($messages[$i]); else $v->setMessage($messages[$i]); $i++; } } } And then in the form : // Construction du formulaire $login = new Zend_Form_Element_Text('txt_Login'); $login->setLabel('Pseudo :') ->addValidator(new Zend_Validate_NotEmpty()); // Validateur n°1 $pass = new Zend_Form_Element_Password('txt_Pass'); $pass->setLabel('Mot de passe :') ->addValidator(new Zend_Validate_NotEmpty()) // Validateur n°2 ->addValidator(new Zend_Validate_StringLength(4, 8)); // Validateur n°3 $submit = new Zend_Form_Element_Submit('bt_Submit'); $submit->setValue('Se connecter'); $form = new Form(); $form->setMethod('post') ->addElement($login) ->addElement($pass) ->addElement($submit); $form->setValidatorMessages(array( 'Le pseudo est obligatoire.', // Message pour le validateur n°1 'Le mot de passe est obligatoire.' // Message pour le validateur n°2 array( // Messages pour le validateur n°3 'Le mot de passe est trop court', 'Le mot de passe est trop long' ) )); Is that already possible or is it required to use this method ? Thanks! :-D Matthew Weier O'Phinney-3 wrote: > > -- Dividy <[EMAIL PROTECTED]> wrote > (on Monday, 04 February 2008, 09:42 AM -0800): >> Thanks for all your good advices. I tried everything you proposed some >> days >> ago and it didn't give any good results. That's why i have come with this >> solution. >> >> But please, if you could give me an example of line you'd put in a csv >> file, >> that would be great :) >> >> e.g. I tried using "isEmpty;The string is empty" in my en.csv file and >> then >> put the translation in my fr.csv file, but it didn't work :) > > You had it right... but there was a problem in trunk... while validation > in the *elements* was getting properly translated, the form object was > not injecting the translator into the elements... oops! > > Corrected now in svn trunk. > > >> Thanks in advance for your precious time. > > And thank you for the issue reporting! > > > -- View this message in context: http://www.nabble.com/Zend_Form-and-validation-language-tp15248574s16154p15289026.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form and validation language
Thanks! :-D Matthew Weier O'Phinney-3 wrote: > > -- Dividy <[EMAIL PROTECTED]> wrote > (on Monday, 04 February 2008, 09:42 AM -0800): >> Thanks for all your good advices. I tried everything you proposed some >> days >> ago and it didn't give any good results. That's why i have come with this >> solution. >> >> But please, if you could give me an example of line you'd put in a csv >> file, >> that would be great :) >> >> e.g. I tried using "isEmpty;The string is empty" in my en.csv file and >> then >> put the translation in my fr.csv file, but it didn't work :) > > You had it right... but there was a problem in trunk... while validation > in the *elements* was getting properly translated, the form object was > not injecting the translator into the elements... oops! > > Corrected now in svn trunk. > > >> Thanks in advance for your precious time. > > And thank you for the issue reporting! > > >> Matthew Weier O'Phinney-3 wrote: >> > >> > -- Dividy <[EMAIL PROTECTED]> wrote >> > (on Monday, 04 February 2008, 06:22 AM -0800): >> >> Dividy wrote: >> >> > For my first post on this nice forum, could someone explain me in >> >> details >> >> > how to translate the error messages of a zend_form validation ? >> >> > >> >> > I tried much thing but none work. >> >> > >> >> > Thanks. >> >> >> >> First, thanks for answering so fast because using Zend every day, is >> just >> >> a >> >> pure pleasure. >> >> >> >> Here's what i had came to while waiting for your answer : >> > >> > Please note my previous response -- this is no longer necessary using >> > the current svn trunk, as getMessages() now translates error messages >> by >> > default if a translate adapter is present and the error code is present >> > in the translations. >> > >> >> > >> >> >> $t=$form->getElements(); >> >> foreach ($t as $element) { >> >> $validateurs=$element->getValidators(); >> >> $validateurs_noms=array_keys($validateurs); >> >> for ($k=0;$k> >> >> >> if >> >> ($validateurs_noms[$k]=='Zend_Validate_StringLength'){ >> >> >> >> $valobj=$element->getValidator($validateurs_noms[$k]); >> >> $valobj->setMessages( array( >> >> >> >> Zend_Validate_StringLength::TOO_SHORT => 'Les données saisies sont >> trop >> >> courtes', >> >> >> >> Zend_Validate_StringLength::TOO_LONG => 'Les données saisies sont >> trop >> >> trop >> >> longues' >> >> )); >> >> } >> >> >> >> if >> >> ($validateurs_noms[$k]=='Zend_Validate_Alnum'){ >> >> >> >> $valobj=$element->getValidator($validateurs_noms[$k]); >> >> $valobj->setMessages( array( >> >> >> >> Zend_Validate_Alnum::STRING_EMPTY => 'Ce champ est requis', >> >> >> >> Zend_Validate_Alnum::NOT_ALNUM => 'Uniquement des chiffres et des >> >> lettres' >> >> )); >> >> } >> >> >> >> if >> >> ($validateurs_noms[$k]=='Zend_Validate_Regex'){ >> >> >> >> $valobj=$element->getValidator($validateurs_noms[$k]); >> >> $valobj->setMessages( array( >> >> >> >> Zend_Validate_Regex::NOT_MATCH => 'Les données ne correspondent pas >> au >> >> format demandé' >> >> )); >> >>
Re: [fw-general] Zend_Form and validation language
Thanks for all your good advices. I tried everything you proposed some days ago and it didn't give any good results. That's why i have come with this solution. But please, if you could give me an example of line you'd put in a csv file, that would be great :) e.g. I tried using "isEmpty;The string is empty" in my en.csv file and then put the translation in my fr.csv file, but it didn't work :) Thanks in advance for your precious time. Matthew Weier O'Phinney-3 wrote: > > -- Dividy <[EMAIL PROTECTED]> wrote > (on Monday, 04 February 2008, 06:22 AM -0800): >> Dividy wrote: >> > For my first post on this nice forum, could someone explain me in >> details >> > how to translate the error messages of a zend_form validation ? >> > >> > I tried much thing but none work. >> > >> > Thanks. >> >> First, thanks for answering so fast because using Zend every day, is just >> a >> pure pleasure. >> >> Here's what i had came to while waiting for your answer : > > Please note my previous response -- this is no longer necessary using > the current svn trunk, as getMessages() now translates error messages by > default if a translate adapter is present and the error code is present > in the translations. > >> > >> $t=$form->getElements(); >> foreach ($t as $element) { >> $validateurs=$element->getValidators(); >> $validateurs_noms=array_keys($validateurs); >> for ($k=0;$k> >> if >> ($validateurs_noms[$k]=='Zend_Validate_StringLength'){ >> >> $valobj=$element->getValidator($validateurs_noms[$k]); >> $valobj->setMessages( array( >> >> Zend_Validate_StringLength::TOO_SHORT => 'Les données saisies sont trop >> courtes', >> >> Zend_Validate_StringLength::TOO_LONG => 'Les données saisies sont trop >> trop >> longues' >> )); >> } >> >> if >> ($validateurs_noms[$k]=='Zend_Validate_Alnum'){ >> >> $valobj=$element->getValidator($validateurs_noms[$k]); >> $valobj->setMessages( array( >> >> Zend_Validate_Alnum::STRING_EMPTY => 'Ce champ est requis', >> >> Zend_Validate_Alnum::NOT_ALNUM => 'Uniquement des chiffres et des >> lettres' >> )); >> } >> >> if >> ($validateurs_noms[$k]=='Zend_Validate_Regex'){ >> >> $valobj=$element->getValidator($validateurs_noms[$k]); >> $valobj->setMessages( array( >> >> Zend_Validate_Regex::NOT_MATCH => 'Les données ne correspondent pas au >> format demandé' >> )); >> } >> >> if >> ($validateurs_noms[$k]=='Zend_Validate_InArray'){ >> >> $valobj=$element->getValidator($validateurs_noms[$k]); >> $valobj->setMessages( array( >> >> Zend_Validate_InArray::NOT_IN_ARRAY => 'Mauvais choix, veuillez >> recommencer' >> )); >> } >> >> if >> ($validateurs_noms[$k]=='Zend_Validate_NotEmpty'){ >> >> $valobj=$element->getValidator($validateurs_noms[$k]); >> $valobj->setMessages( array( >> >> Zend_Validate_NotEmpty::IS_EMPTY => 'Le champ est vide, veuillez le >> remplir' >> )); >> } >> >> if >> ($validateurs_noms[$k]=='Zend_Validate_EmailAddress
Re: [fw-general] Zend_Form and validation language
Dividy wrote: > > Hello all :) > > For my first post on this nice forum, could someone explain me in details > how to translate the error messages of a zend_form validation ? > > I tried much thing but none work. > > Thanks. > First, thanks for answering so fast because using Zend every day, is just a pure pleasure. Here's what i had came to while waiting for your answer : getElements(); foreach ($t as $element) { $validateurs=$element->getValidators(); $validateurs_noms=array_keys($validateurs); for ($k=0;$kgetValidator($validateurs_noms[$k]); $valobj->setMessages( array( Zend_Validate_StringLength::TOO_SHORT => 'Les données saisies sont trop courtes', Zend_Validate_StringLength::TOO_LONG => 'Les données saisies sont trop trop longues' )); } if ($validateurs_noms[$k]=='Zend_Validate_Alnum'){ $valobj=$element->getValidator($validateurs_noms[$k]); $valobj->setMessages( array( Zend_Validate_Alnum::STRING_EMPTY => 'Ce champ est requis', Zend_Validate_Alnum::NOT_ALNUM => 'Uniquement des chiffres et des lettres' )); } if ($validateurs_noms[$k]=='Zend_Validate_Regex'){ $valobj=$element->getValidator($validateurs_noms[$k]); $valobj->setMessages( array( Zend_Validate_Regex::NOT_MATCH => 'Les données ne correspondent pas au format demandé' )); } if ($validateurs_noms[$k]=='Zend_Validate_InArray'){ $valobj=$element->getValidator($validateurs_noms[$k]); $valobj->setMessages( array( Zend_Validate_InArray::NOT_IN_ARRAY => 'Mauvais choix, veuillez recommencer' )); } if ($validateurs_noms[$k]=='Zend_Validate_NotEmpty'){ $valobj=$element->getValidator($validateurs_noms[$k]); $valobj->setMessages( array( Zend_Validate_NotEmpty::IS_EMPTY => 'Le champ est vide, veuillez le remplir' )); } if ($validateurs_noms[$k]=='Zend_Validate_EmailAddress'){ $valobj=$element->getValidator($validateurs_noms[$k]); $valobj->setMessages( array( Zend_Validate_EmailAddress::INVALID => 'Adresse e-mail invalide, veuillez la vérifier', Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'Adresse e-mail invalide, veuillez la vérifier', Zend_Validate_EmailAddress::INVALID_LOCAL_PART=> 'Adresse e-mail invalide, veuillez la vérifier', Zend_Validate_EmailAddress::INVALID_MX_RECORD => 'Adresse e-mail invalide, veuillez la vérifier' )); } } } ?> -- View this message in context: http://www.nabble.com/Zend_Form-and-validation-language-tp15248574s16154p15268761.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form and validation language
Hello all :) For my first post on this nice forum, could someone explain me in details how to translate the error messages of a zend_form validation ? I tried much thing but none work. Thanks. -- View this message in context: http://www.nabble.com/Zend_Form-and-validation-language-tp15248574s16154p15248574.html Sent from the Zend Framework mailing list archive at Nabble.com.