Zend_Form validator custom error message in INI configuration file

天大地大妈咪最大 提交于 2020-01-14 03:01:08

问题


I am using INI files to manage my Zend_Form elements.

Here's an example .ini file:

form.action = ""
form.method = "post

form.elements.attribute_name.type = "text"
form.elements.attribute_name.options.label = "Element Name"
form.elements.attribute_name.options.validators.strlen.validator = "StringLength"
form.elements.attribute_name.options.validators.strlen.options.min = "1"
form.elements.attribute_name.options.validators.strlen.options.max = "50"

form.elements.submit.type = "submit"
form.elements.submit.options.name = "Go!"

This element will throw the "strlen" error message as "XX is greater than 50 characters long"

My question is: How do i overwrite this error message within in INI file?

I thought the following might work, but it doesnt do anything!

form.elements.attribute_name.options.validators.strlen.options.message = "You Muppet!"

Thanks for any help.

Jon


回答1:


I think you need to select which specific validation message you want to override.

Try this:

form.elements.attribute_name.options.validators.strlen.options.messages.stringLengthInvalid = "You Muppet!"
form.elements.attribute_name.options.validators.strlen.options.messages.stringLengthTooShort = "You Muppet!"
form.elements.attribute_name.options.validators.strlen.options.messages.stringLengthTooLong = "You Muppet!"

Of course, I could be wrong!




回答2:


Bingo! Thanks to Rob Allen's post I've managed to figure it out. The correct INI code is:

form.elements.attribute_page.options.validators.strlen.options.messages.stringLengthTooLong = "You Muppet!"

Thanks Rob!



来源:https://stackoverflow.com/questions/1396348/zend-form-validator-custom-error-message-in-ini-configuration-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!