You can use $input->getErrors() instead of
$input->getMessages(). The
validator getErrors() method returns language-independent
values for the
type of validation failure. These are actually the const
identifiers
you list below.
Then you can map that to application error message in any
way you want.
Maybe in your application, the type of error is not
significant, and any
case that makes isValid() return false should map to a
single error
message, as you describe.
Another solution would be to extend Zend_Validate_Hostname
as
Croatian_Validate_Hostname, and override the message
definition with
translated strings. Then add "Croatian_Validate"
as a namespace for
Zend_Filter_Input, so it finds a custom validator class (if
it exists)
before it finds Zend_Validate_Hostname.
Regards,
Bill Karwin
> -----Original Message-----
> From: Boris Tomic [mailto:kodmasin gmail.com]
> Sent: Wednesday, August 29, 2007 1:03 PM
> To: fw-general lists.zend.com
> Subject: [fw-general] Zend_Input_Filter (Zend_Validate)
> custom error messages
>
>
> Hi
>
> I really like Zend_Input_Filter as it quite easy and
fast to
> write validators. My only complain is that I have to
write
> many custom error messages as I am Croatian. So for
example
> if I use EmailAddress Validator I have to translate:
>
> Zend_Validate_EmailAddress::INVALID
> Zend_Validate_EmailAddress::INVALID_HOSTNAME
> Zend_Validate_EmailAddress::INVALID_MX_RECORD
> Zend_Validate_EmailAddress: OT_ATOM
> Zend_Validate_EmailAddress::QUOTED_STRING
> Zend_Validate_EmailAddress::INVALID_LOCAL_PART
>
> and
>
> Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED
> Zend_Validate_Hostname::UNKNOWN_TLD
> Zend_Validate_Hostname::INVALID_DASH
> Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA
> Zend_Validate_Hostname::UNDECIPHERABLE_TLD
> Zend_Validate_Hostname::INVALID_HOSTNAME
> Zend_Validate_Hostname::INVALID_LOCAL_NAME
> Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED
>
> As you can see that is quite lot messages to write and
some
> of them are even confusing and to detailed even English
> speaking people. Ok I can understand that this messages
are
> not intended for end user but it will be a nice feature
that
> I can set one messages ("You have entered wrong
email
> address") for all types of errors easily. Does
this exists?
> If not what will be best way to accomplish this.
>
> Tnx
>
> Boris
> --
> View this message in context:
> http://www.nabble.com/Zend_Input_Filter-%28Zend_Va
lidate%29-cu
> stom-error-messages-tf4350064s16154.html#a12394734
> Sent from the Zend Framework mailing list archive at
Nabble.com.
>
>
|