Jump to content

[design] Validation of both programmatic and manual input


Recommended Posts



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?

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.