I want to change the default error messages "No token was provided to match against" and "The two given tokens do not match". For the second one (tokens don't match), I thought readding the Identical validator would do it, but in the form I don't have access to the $value_to_match_against
so maybe this is the wrong way. For the first one (no token provided), I don't know how to change it at al开发者_运维技巧l.
->addValidator('Identical', true, $value_to_match_against, $msg);
A simple search on Stack Overflow gives quite a lot of different way to do it:
- By using .ini files
- Altering the element or using SetMessages
- Using options in an array definition
- Using translation files
All these ways are valid, choosing the best depends on how you manage your code/application/classes. The most important point is to get either the name or the constant of the available error messages. You can find they quite easily by reading the source code of the Validator you are using (usually on top of these files), or by using the translation files.
If you are trying to do this via an ini, the structure is slightly different:
elements.csrf.options.errorMessages.Identical = "This form has timed out for secrity purposes. Please try again."
精彩评论