validation rules and their returning messages

24 views
Skip to first unread message

euromark

unread,
Jul 21, 2011, 6:44:58 PM7/21/11
to cakephp-core
it sometimes bugged me in the past that those messages are kinda
fixed.
they cannot really be modified or used with placeholders.

lets imagine:
rule => min, 6
message => "You should at least provide 6 chars"

we cannot pass in the current char count.
I would like to return: "You should at least provide 6 chars -
currently its just 4" or "You should at least provide 6 chars - 2 more
please!"
From my tests it seemed that you cannot access (or access but not
change!) the validation message inside a custom validation method.
Maybe it is possible to make the validation itself more robust as it
used to be all those previous versions of cake?
just something it was thinking about today.

euromark

unread,
Jul 21, 2011, 7:37:14 PM7/21/11
to cakephp-core
i also like to use the following syntax:

'pwd' => array(
'between' => array(
'rule' => array('between', PWD_MIN_LENGTH, PWD_MAX_LENGTH),
'message' => array('Your password needs to be between %s and %s
chars long', PWD_MIN_LENGTH, PWD_MAX_LENGTH),
)
),

a little change in the invalidate() function makes it possible to use
i18n here a little bit better. it checks the arguments and if
available uses sprintf() here.
imagine we would have to translate every possible string with the 2
integer values. this way its just one.
is this worth to be considered an improvement for future versions?


combined with my previous post maybe sth like this could be possible
one day:
"Your password needs to be between %s and %s chars long - currently
its just :length chars"
which then uses String::insert() at some point in the script.
the only thing I cannot figure out is how to best provide the data
like current length or the string itself in invalidate().
at last I could't figure out a clean approach.
Reply all
Reply to author
Forward
0 new messages