[FLOW3-general] Issues with Validation and Property Mapping
Adrian Föder
adrian at foeder.de
Tue Apr 17 11:46:06 CEST 2012
Hi List,
after wondering and stepping through the processing, I found that
obviously the following situation is present.
I have a Model Object that has, besides others, a (float)`price`
attribute. A website user should be able to set that property.
I as the "designer" want to have that validation very pessimistic,
meaning if somebody enters "10foo" it should result in an error.
An additional very important task is to care about the Locale, meaning
of course 10.00 and 10,00 means both "ten bucks" depending on the user's
locale.
I attached the NotEmpty- and the NumberValidator to the property and
both didn't work. They seemed to not kick in.
After, as said, debugging through I found out that the validators are
confrontated with a value of `0`, so both the NotEmpty and Number were
satisfied, whereas the actual provided value (in the form) was "".
Interestingly, the only context where the validation at all took place
was the GenericObjectValidator that got the whole, already-mapped object
and did its validation.
So I assume the property mapper built the object from the array source,
some kind of PHP's auto-casting took place when it came to convert "" or
"10foo" to float, both resulting in 0.
Afterwards, the whole object was passed to the GenericObjectValidator,
having already `0` as price.
So, I have now two questions:
- is my observation correct and intended?
- what should I do to achieve what I want? I indeed want to test the
value kind-of on a string basis... As said: I have to be very
pessimistic and decline the input if there's *anything* wrong there...
Thanks a lot :)
Best,
adrian
More information about the FLOW3-general
mailing list