Luis Majano Forums Notification: Post to Form Validation

Title: RE: Form Validation
Thread: Form Validation
Forum: Need Help?
Conference: ColdBox
User: lmajano

Hi tszao,

There are so many ways to do validation and doing handler
validation is one of them. In a more enterprise application in which I have
domain model objects I would create my objects have their own validate()
methods. I would then use the beanfactory plugin to populate them with data
from the request collection and then validate.

To give you an example, let
say you have a cfc that models an address.


Then your cfc would have the getters and setters for this
properties. You can take a look at Brian Rinaldis cfc generator to generate your

Then you would create a validate() method in your address cfc that
validates the properties and returns a boolean.

//Inside the
handler, in a form submit
oAddress =
//populate address object with form
//Validate the bean
if (
oAddress.validate() ){
  //send or save;
  errors = oAddress.getErrors();
  //redirect to error page.

There is more to it, you can create an error
string property in your address cfc to hold errors and then you can retrieve
them for display. This method is called form bean validations.

As you can
see, validations can be done in several ways, I see no mistakes in validating
directly in the handler or withing your domain beans. It all depends on your
design and how OO your application is. Hope this helps?