rubenski Posted December 11, 2009 Share Posted December 11, 2009 Hello, Imagine you have a 'car' system. It has a HTML form for entering cars (brand, name, year, color, etc), but you also want to allow client programmers to enter and edit cars programmatically through a CarManager object, for example through CarManager::addCar(Car $newCar) Ideally, I want to use the addCar() method for each Car insertion, either through the HTML form or through client programmer's code, but I think both have different requirements for validation information. - The HTML form requires a valid/invalid indicator and in case of invalid input a set (array?) of error messages that can be displayed under fields that contain erroneous input. The form wants to know all errneous fields and their specific problems at once, so it can display all problems to the user at once. - The client programmer would probably be most familiair with an Exception that is thrown when invalid data is found in one of the $car's fields. I currently return either 'true' or an array of FieldValidator objects containing per-field error messages from the addCar() method. This is perfect for the HTML form, but not for client programmer code. Next possible solution is to create a custom Exception containing a generic error message and an array of per-field error messages? What would you do? Quote Link to comment https://forums.phpfreaks.com/topic/184814-design-validation-of-both-programmatic-and-manual-input/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.