So, I have a problem when using filters in forms in Zend Framework.
When you set a filter on your form element, it filters the data provided to element, in all ways. So, if I call isValid() on the form, a ‘Int’ filter will convert the string “1” to an int 1. But if I set the element’s value to a string “1”, that value still will be converted to an int 1.
That behavior brings me a problem. For example, by the rules of the enterprise, all float value must be multiplied by 100 before save it to db (yeah, that sucks). So, i created a filter for that, and 10 becomes 1000. But when populate the form, 1000 becomes 100000.
I want a way to do that without work that in the model, only in the form. So, i thought to create a flag, to specify when the filter should be called.
Is there a better way to do that? I swear I did looked for that around, but I didn’t find anything.
Thanks.
What is in the database and what is in your model is part of the model-layer. In this case the mapper should take care of converting. You should not move this to the form, which is in fact more part of the view-layer, than anything else.