 |
Zend Framework, Model Validation? |
May 8, 2008
Today while reading what little traffic arrives to the Zend Framework list, some poor user posted this:
How would you go about displaying a custom error message when a sub
form fails validation? i.e. I've overloaded the subform's isValid()
method to add some custom validation thats reliant on a combination of
all the fields in the subform, if this fails I'd like to pass an error
message to surround the subform as with individual form elements.
Output and decoration issues aside, I can't even see how to log the
error anywhere I'm afraid.
This post emphasizes the point I made previously about how Zend Framework doesn't provide data validation in the model itself, rather it's out there in the form instead. This mis-wiring is a complete catastrophe when you are entering data for dependent models in the same form, not to mention you have to provide validation for all forms, not matter how many times the same model might appear on a site.
In Ruby on Rails data is validated in the model. When multiple models exists on the same form one only has to interrogate the model for any validation errors.
|
Validation should indeed be handled by the model
By: Eran Galperin <eran at octabox dot com>
Posted: 2 months ago
I completely agree with what you wrote. I wrote a fairly technical article about models in the Zend Framework and suggested a validation / Zend_Db_Table combo approach.
http://www.techfounder.net/2008/05/21/models-in-the-zend-framework-part-2/