|
Are you using a bean to persist your form's submitted values? What i do, cuz i'm a little intellectually lazy, like Ray, is to place a validate function in my bean. Others abstract the validation to a separate object, but i prefer having it in one package. It's just a little easier for me to see what's going on. Once reactor is stable, i'll probably move to using that. If you need an example to work off of, i've pasted one below: <cfcomponent displayName="Visitor" hint="I'm a Visitor that fills out a contact form" output="false"> <cfinclude template="../udfs/IsEmail.cfm" /> <cffunction name="init" access="public" returntype="any" output="false"> <cfargument name="title" type="string" required="false" default="" /> <cfargument name="fname" type="string" required="false" default="" /> <cfargument name="lname" type="string" required="false" default="" /> <cfargument name="email" type="string" required="false" default="" /> <cfargument name="phone" type="string" required="false" default="" /> <cfargument name="bestTime" type="string" required="false" default="" /> <cfargument name="address1" type="string" required="false" default="" /> <cfargument name="address2" type="string" required="false" default="" /> <cfargument name="city" type="string" required="false" default="" /> <cfargument name="postalCode" type="string" required="false" default="" /> <cfargument name="country" type="string" required="false" default="" /> <cfargument name="text" type="string" required="false" default="" /> <cfargument name="replyLanguage" type="string" required="false" default="" /> <cfargument name="contactMode" type="string" required="false" default="" /> <cfargument name="projectId" type="string" required="false" default="" /> <cfargument name="subscribeMe" type="boolean" required="false" default="true" /> <cfargument name="contactMe" type="boolean" required="false" default="true" /> <cfargument name="requiredFields" type="string" required="false" default="" hint="a comma delimited list of required fields, can be defaulted here" /> <cfset setInstanceFromStruct(arguments) /> <cfset variables.requiredFields = arguments.requiredFields /> <cfset variables.invalidFields = "" /> <cfset variables.missingFields = "" /> <cfreturn this /> </cffunction> <cffunction name="getInstanceAsStruct" access="public" returntype="struct" output="false"> <cfset var returnData = StructNew() /> <cfset returnData.title = getTitle() /> <cfset returnData.fname = getFname() /> <cfset returnData.lname = getLname() /> <cfset returnData.email = getEmail() /> <cfset returnData.phone = getPhone() /> <cfset returnData.bestTime = getBestTime() /> <cfset returnData.address1 = getAddress1() /> <cfset returnData.address2 = getAddress2() /> <cfset returnData.city = getCity() /> <cfset returnData.postalCode = getPostalCode() /> <cfset returnData.country = getCountry() /> <cfset returnData.text = getText() /> <cfset returnData.replyLanguage = getReplyLanguage() /> <cfset returnData.contactMode = getContactMode() /> <cfset returnData.projectId = getProjectId() /> <cfset returnData.subscribeMe = getSubscribeMe() /> <cfset returnData.contactMe = getContactMe() /> <cfreturn returnData /> </cffunction> <cffunction name="setInstanceFromStruct" access="public" returntype="any" output="false"> <cfargument name="data" required="true" type="struct" hint="The struct containing the data to set." /> <cfscript> if(structKeyExists(data,"title")){ setTitle(data.title); } if(structKeyExists(data,"fname")){ setFname(data.fname); } if(structKeyExists(data,"lname")){ setLname(data.lname); } if(structKeyExists(data,"email")){ setEmail(data.email); } if(structKeyExists(data,"phone")){ setPhone(data.phone); } if(structKeyExists(data,"bestTime")){ setBestTime(data.bestTime); } if(structKeyExists(data,"address1")){ setAddress1(data.address1); } if(structKeyExists(data,"address2")){ setAddress2(data.address2); } if(structKeyExists(data,"city")){ setCity(data.city); } if(structKeyExists(data,"postalCode")){ setPostalCode(data.postalCode); } if(structKeyExists(data,"country")){ setCountry(data.country); } if(structKeyExists(data,"text")){ setText(data.text); } if(structKeyExists(data,"replyLanguage")){ setReplyLanguage(data.replyLanguage); } if(structKeyExists(data,"contactMode")){ setContactMode(data.contactMode); } if(structKeyExists(data,"projectId")){ setProjectId(data.projectId); } if(structKeyExists(data,"subscribeMe")){ setSubscribeMe(true); } else { setSubscribeMe(false); } if(structKeyExists(data,"contactMe")){ setContactMe(data.contactMe); } else { setContactMe(false); } </cfscript> <cfreturn this /> </cffunction> <cffunction name="validate" access="public" returntype="boolean" output="no"> <cfset var valid = true /> <cfset variables.invalidFields = "" /> <cfset variables.missingFields = "" /> <cfloop list="#variables.requiredFields#" index="key"> <cfif Len(variables.instance[key]) EQ 0> <cfset variables.missingFields = listAppend(variables.missingFields,"#key#") /> <cfset valid = false> </cfif> </cfloop> <cfif Len(getEmail()) AND NOT IsEmail(getEmail())> <cfset variables.invalidFields = listAppend(variables.invalidFields,"email") /> <cfset valid = false /> </cfif> <cfreturn valid> </cffunction> <cffunction name="getValidationIndex" access="public" returntype="struct" output="false" hint="I return a structure that indicates the validation results for the interface"> <cfset var key = "" /> <cfset var val = StructNew() /> <cfscript> val.email=''; val.displayMissingMessage = false; val.displayInvalidMessage = false; val.isValid = true; </cfscript> <cfif Len(getMissingFields())> <cfloop index="key" list="#getMissingFields()#"> <cfset val[key] = "missing" /> </cfloop> <cfset val.displayMissingMessage = true /> <cfset val.isValid = false /> </cfif> <cfif Len(getInvalidFields())> <cfloop index="key" list="#getInvalidFields()#"> <cfset val[key] = "invalid" /> </cfloop> <cfset val.displayInvalidMessage = true /> <cfset val.isValid = false /> </cfif> <cfreturn val /> </cffunction> <cffunction name="getMissingFields" access="public" returntype="string" output="false"> <cfreturn variables.missingFields /> </cffunction> <cffunction name="getInvalidFields" access="public" returntype="string" output="false"> <cfreturn variables.invalidFields /> </cffunction> <cffunction name="getTitle" access="public" returntype="string" output="false"> <cfreturn variables.instance.title /> </cffunction> <cffunction name="setTitle" access="private" returntype="VOID" output="false"> <cfargument name="title" type="string" required="true" /> <cfset variables.instance.title = arguments.title /> </cffunction> <cffunction name="getFname" access="public" returntype="string" output="false"> <cfreturn variables.instance.fname /> </cffunction> <cffunction name="setFname" access="private" returntype="VOID" output="false"> <cfargument name="fname" type="string" required="true" /> <cfset variables.instance.fname = arguments.fname /> </cffunction> <cffunction name="getLname" access="public" returntype="string" output="false"> <cfreturn variables.instance.lname /> </cffunction> <cffunction name="setLname" access="private" returntype="VOID" output="false"> <cfargument name="lname" type="string" required="true" /> <cfset variables.instance.lname = arguments.lname /> </cffunction> <cffunction name="getEmail" access="public" returntype="string" output="false"> <cfreturn variables.instance.email /> </cffunction> <cffunction name="setEmail" access="private" returntype="VOID" output="false"> <cfargument name="email" type="string" required="true" /> <cfset variables.instance.email = arguments.email /> </cffunction> <cffunction name="getPhone" access="public" returntype="string" output="false"> <cfreturn variables.instance.phone /> </cffunction> <cffunction name="setPhone" access="private" returntype="VOID" output="false"> <cfargument name="phone" type="string" required="true" /> <cfset variables.instance.phone = arguments.phone /> </cffunction> <cffunction name="getBestTime" access="public" returntype="string" output="false"> <cfreturn variables.instance.bestTime /> </cffunction> <cffunction name="setBestTime" access="private" returntype="VOID" output="false"> <cfargument name="bestTime" type="string" required="true" /> <cfset variables.instance.bestTime = arguments.bestTime /> </cffunction> <cffunction name="getAddress1" access="public" returntype="string" output="false"> <cfreturn variables.instance.address1 /> </cffunction> <cffunction name="setAddress1" access="private" returntype="VOID" output="false"> <cfargument name="address1" type="string" required="true" /> <cfset variables.instance.address1 = arguments.address1 /> </cffunction> <cffunction name="getAddress2" access="public" returntype="string" output="false"> <cfreturn variables.instance.address2 /> </cffunction> <cffunction name="setAddress2" access="private" returntype="VOID" output="false"> <cfargument name="address2" type="string" required="true" /> <cfset variables.instance.address2 = arguments.address2 /> </cffunction> <cffunction name="getCity" access="public" returntype="string" output="false"> <cfreturn variables.instance.city /> </cffunction> <cffunction name="setCity" access="private" returntype="VOID" output="false"> <cfargument name="city" type="string" required="true" /> <cfset variables.instance.city = arguments.city /> </cffunction> <cffunction name="getPostalCode" access="public" returntype="string" output="false"> <cfreturn variables.instance.postalCode /> </cffunction> <cffunction name="setPostalCode" access="private" returntype="VOID" output="false"> <cfargument name="postalCode" type="string" required="true" /> <cfset variables.instance.postalCode = arguments.postalCode /> </cffunction> <cffunction name="getCountry" access="public" returntype="string" output="false"> <cfreturn variables.instance.country /> </cffunction> <cffunction name="setCountry" access="private" returntype="VOID" output="false"> <cfargument name="country" type="string" required="true" /> <cfset variables.instance.country = arguments.country /> </cffunction> <cffunction name="getText" access="public" returntype="string" output="false"> <cfreturn variables.instance.text /> </cffunction> <cffunction name="setText" access="private" returntype="VOID" output="false"> <cfargument name="text" type="string" required="true" /> <cfset variables.instance.text = arguments.text /> </cffunction> <cffunction name="getReplyLanguage" access="public" returntype="string" output="false"> <cfreturn variables.instance.replyLanguage /> </cffunction> <cffunction name="setReplyLanguage" access="private" returntype="VOID" output="false"> <cfargument name="replyLanguage" type="string" required="true" /> <cfset variables.instance.replyLanguage = arguments.replyLanguage /> </cffunction> <cffunction name="getContactMode" access="public" returntype="string" output="false"> <cfreturn variables.instance.contactMode /> </cffunction> <cffunction name="setContactMode" access="private" returntype="VOID" output="false"> <cfargument name="contactMode" type="string" required="true" /> <cfset variables.instance.contactMode = arguments.contactMode /> </cffunction> <cffunction name="getProjectId" access="public" returntype="string" output="false"> <cfreturn variables.instance.ProjectId /> </cffunction> <cffunction name="setProjectId" access="public" returntype="VOID" output="false"> <cfargument name="ProjectId" type="string" required="true" /> <cfset variables.instance.ProjectId = arguments.ProjectId /> </cffunction> <cffunction name="getSubscribeMe" access="public" returntype="boolean" output="false"> <cfreturn variables.instance.subscribeMe /> </cffunction> <cffunction name="setSubscribeMe" access="private" returntype="VOID" output="false"> <cfargument name="subscribeMe" type="boolean" required="true" /> <cfset variables.instance.subscribeMe = arguments.subscribeMe /> </cffunction> <cffunction name="getContactMe" access="public" returntype="any" output="false"> <cfreturn variables.instance.contactMe /> </cffunction> <cffunction name="setContactMe" access="private" returntype="VOID" output="false"> <cfargument name="contactMe" type="any" required="true" /> <cfset variables.instance.contactMe = arguments.contactMe /> </cffunction> </cfcomponent> ciao, Nando Jason Daiger wrote:
|
- [CFCDev] Model or View? Jason Daiger
- Re: [CFCDev] Model or View? Cody Caughlan
- Re: [CFCDev] Model or View? Nando
- RE: [CFCDev] Model or View? Peter Bell
- RE: [CFCDev] Model or View? Jason Daiger
- RE: [CFCDev] Model or View? Peter Bell
- RE: [CFCDev] Model or View? RADEMAKERS Tanguy
- RE: [CFCDev] Model or View? Peter Bell
- RE: [CFCDev] Model or View? Jason Daiger
- RE: [CFCDev] Model or View? Peter Bell
- Re: [CFCDev] Model or View? Cliff Meyers
- RE: [CFCDev] Model or View? Peter Bell
- Re: [CFCDev] Model or View? Chris Scott

