Jump to content

[design] Validation of both programmatic and manual input


rubenski

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.