Hi Anthony

Couple of thoughts:

Common data type validations ( isEmail(), isCreditCard(), isPhoneNumber() )
could go into a shared Validator.cfc

Beans may have a validate() function to ensure their data is valid within
the bean itself.

Business logic that requires knowledge beyond a single bean needs to go
elsewhere - perhaps in a Service component or a helper type object.

I like the idea of a 'helper' object that is aware of all fields within the
form - which may span many beans. This object can receive the 'form' data in
a single struct and knows how to extract all the data it needs and convert
to the required beans. It then may call the individual beans validate()
functions, then perform any cross-bean validation.

This is also quite nice for redisplaying the form populated with the
originally entered data as all of the data is still in a single un-altered
place.

I wrote some thoughts on this a little while ago. I also appreciate any
thoughts you may have:

http://www.stannard.net.au/blog/index.cfm/2007/1/11/Simple-Object-Oriented-F
orm-Handling

Regards

Kevan

________________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Anthony
Tinoco
Sent: Friday, 1 June 2007 8:32 AM
To: cfcdev@cfczone.org
Subject: [CFCDEV] form validation - where does it belong?

Hi All,

As my understanding of cfc development has increased, I am still left
wanting in my understanding of where to put form validation logic.

Currently, I am putting the form validation logic in the business objects,
such as is the form field blank, is it a credit card, is it a phone number,
is it an e-mail address, etc.  It just seems like this stuff should be
handled before getting to the business object.

Maybe this comes from my previous experience of working with the Struts
Framework which removed form validation logic from the business objects.

Would it be best to handle this stuff in a separate validation.cfc which
would validate the form and then create a form bean to be passed to the
business object upon successful validation?

Thoughts would be greatly appreciated on this subject,

Anthony



You are subscribed to cfcdev. To unsubscribe, please follow the instructions at 
http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org

Reply via email to