> Should read: As for 'sharing' variables between *methods*
I picked up on that one. :o) Thanks for the feedback. I'll give it some thought and see what happens. Rick Dominic Watson wrote: > Sorry, hungover > > >> <cffunction method="init" ...> >> <cfargument name="adminEmail" .../> >> <cfset _adminEmail = arguments.adminEmail /> >> <cfreturn _adminEmail /> >> </cffunction> >> > > Should read: > > <cffunction method="init" ...> > <cfargument name="adminEmail" .../> > <cfset _adminEmail = arguments.adminEmail /> > <cfreturn this /> > </cffunction> > > And: > > >> As for 'sharing' variables between arguments within a single cfc... >> > > Should read: As for 'sharing' variables between *methods* within a > single cfc... > > > ! Dominic > > 2008/11/1 Dominic Watson <[EMAIL PROTECTED]>: > >> Personally, I'd prefer the first approach. The validation method >> should only be concerned with validating the form; it should not know >> what to do if the form validates. However, it *would* make sense to do >> it the other way around; ie. call the email method, which first calls >> the validation method and acts accordingly. >> >> As for 'sharing' variables between arguments within a single cfc, I'd >> say you would always want to use the arguments scope for passing the >> data around. Both these choices make for maximising the reusability of >> your code. >> >> Consider: >> >> <cfcomponent output="false"> >> <cfset variables._adminEmail = "" /> >> >> <cffunction method="init" ...> >> <cfargument name="adminEmail" .../> >> <cfset _adminEmail = arguments.adminEmail /> >> <cfreturn _adminEmail /> >> </cffunction> >> >> <cffunction name="validateData"...><!--- uber simplified for sake >> of example ---> >> <cfargument name="foo" ... /> >> <cfargument name="bar" ... /> >> >> <cfif not Len(Trim(arguments.foo))> >> <cfreturn false /> >> </cfif> >> <cfif not Len(Trim(arguments.bar))> >> <cfreturn false /> >> </cfif> >> >> <cfreturn true /> >> </cffunction> >> >> <cffunction name="sendEmail" ...> >> <cfargument name="foo" ... /> >> <cfargument name="bar" ... /> >> >> <cfif not ValidateData(arguments.foo, arguments.bar)><!--- >> or ValidateData(argumentCollection = arguments) would be fine ---> >> <!--- some error handling code ---> >> <cfelse> >> <cfmail from="#_adminEmail#" to="#arguments.foo#" >> subject="#arguments.bar#" ...> >> Hello world. >> </cfmail> >> </cfif> >> </cffunction> >> </cfcomponent> >> >> <!---- calling .cfm template ---> >> <cfscript> >> myComponent.sendEmail(argumentCollection = form); >> </cfscript> >> >> One final thing I would say is that, personally, I prefer not to use >> argumentCollection if it is practical not to do so. If you know what >> variables need to be passed from the form scope, write them out >> explicitly; it will help with readability, ie. >> >> myComponent.sendEmail( form.foo, form.bar ); >> >> I find argumentCollection really useful when needing to send in a >> dynamic amount of arguments when there are lots of optional arguments >> for a function. A good example would be in a reporting function that >> takes several filters. So: >> >> filters = structNew(); >> if(form.filterX NEQ 'any') >> filters.filterX = form.filterX; >> if(form.filterY NEQ 0) >> filters.filterY = form.filterY; >> >> myComponent.getReport( argumentCollection = filters ) >> >> HTH >> >> Dominic >> >> 2008/11/1 Rick Faircloth <[EMAIL PROTECTED]>: >> >>> Hi, Dominic and thanks for the reply... >>> >>> The second option sounds more like what I'm wanting to do. >>> >>> And while reading your response, it occurred to me that if I >>> send the form data to a cfc for validation, and it validates, >>> I could just go straight to another method (how about to another cfc?) >>> for the email processing >>> without going back to the orginal form page and then to the >>> email processing cfc. (make sense?) >>> >>> So, I would go from form page to validation method, and if all validates, >>> straight to the email method to send emails. >>> >>> And from your description below, I would just refer to the >>> arguments.variables >>> in the second method as in the first? No, I guess I couldn't use the >>> "arguments" scope >>> and share variables between methods...I'd need to put the data into the >>> "variables" scope >>> to share between methods. Right? >>> >>> And, if that's so, I guess each form variable has to be established in >>> the first validation >>> method by translating each piece of data in to the variable scope with >>> <cfset variables.name = arguments.name> in order to share those >>> variables within a CFC. >>> >>> Am I correct? >>> >>> Thanks for the feedback. >>> >>> Rick >>> >>> Dominic Watson wrote: >>> >>>> Something like this? >>>> >>>> <cfif someObject.validateTheForm(argumentCollection = form) > >>>> <cfset variables.foo = >>>> anotherObject.doSomethingWithForm(argumentCollection = form) /> >>>> <cfelse> >>>> Form did not validate >>>> </cfif> >>>> >>>> Or, are you wanting to pass the form data to another cfc method from >>>> within the validation method? If so, something like this: >>>> >>>> <cffunction name="validateTheForm" ...> >>>> <cfargument name="foo" ... /> >>>> <cfargument name="bar" ... /> >>>> >>>> <cfscript> >>>> ... >>>> someOtherObject.doSomethingWithFormData( argumentCollection = >>>> arguments ) ; >>>> ... >>>> </cfscript> >>>> </cffunction> >>>> >>>> Dominic >>>> >>>> 2008/11/1 Rick Faircloth <[EMAIL PROTECTED]>: >>>> >>>> >>>>> Hi, all... >>>>> >>>>> Can form variables be passed around between a calling page and >>>>> multiple cfc's? >>>>> >>>>> I have a form with data I want to validate, then generate an email with. >>>>> >>>>> I have the calling page with the form, which sends the form data via >>>>> argumentCollection, >>>>> to a form_validation.cfc. If the form data passes validation, then I >>>>> want to send the form >>>>> data to an email_processing.cfc for email generation. >>>>> >>>>> Would the form variables be available to the calling page and both cfc's >>>>> in this case? >>>>> Or do I need to create session variables or another type of variable to >>>>> pass the values >>>>> around? >>>>> >>>>> Thanks, >>>>> >>>>> Rick >>>>> >>>>> >>>>> >>>>> >>>> >>> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314723 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

