passing entire form collection to cfargument??? can it be done? should it be done

Hello experts, I've dozens and dozens and dozens of form vars passing to a CFC, can I pass the entire collection to an argument (rather than creating an argument for each var?)  I found some code on this forum, but it a) can't figure out how to make it work and b) not sure if it's "best practice".

<cfset objIndexedAnnuities = createObject("component", "/cfc/indexedAnnuities")/>
<cfset objIndexedAnnuities.updateSubmission(argumentCollection=form)/>

<cffunction name="updateSubmission" access="public" returntype="boolean" output="false" hint="Update Indexed Annuity approval submission">

<!--- can this one argument contain the entire form structure? --->
<cfargument name="formStructure" required="yes" type="struct">

<cfquery datasource="datasource">
UPDATE tableName
SET repName=<cfqueryparam  cfsqltype="string" value="#arguments.repName#"/>,
repNo=<cfqueryparam  cfsqltype="string" value="#arguments.repNo#"/>,
writingRep=<cfqueryparam  cfsqltype="string" value="#arguments.writingRep#"/>,
otherPartiesName=<cfqueryparam  cfsqltype="string" value="#arguments.otherPartiesName#"/>,
ownerSalutation=<cfqueryparam  cfsqltype="string" value="#arguments.ownerSalutation#"/>,
ownerFirstName=<cfqueryparam  cfsqltype="string" value="#arguments.ownerFirstName#"/>,
ownerMiddleName=<cfqueryparam  cfsqltype="string" value="#arguments.ownerMiddleName#"/>,
ownerLastName=<cfqueryparam  cfsqltype="string" value="#arguments.ownerLastName#"/>,
dateOfBirth=<cfqueryparam  cfsqltype="date" value="#arguments.dateOfBirth#"/>,
age=<cfqueryparam  cfsqltype="numeric" value="#arguments.age#"/>,

etc, etc, etc.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


A form is a structure.

<cfargument name="formStructure" required="yes" type="struct" />

then just pass the variable form in.

<cfset objIndexedAnnuities = createObject("component", "/cfc/indexedAnnuities")/>
<cfset objIndexedAnnuities.updateSubmission(form)/>

Then just access them. as if they were form variables, but using formStructure. in stead of form.

ie: form.repName would be accessed as formStructure.repName


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I definitely consider this a 'best practice'.  I usually develop my applications so that the ENTIRE logic layer is handled by component functions and only the view layer is handled on an individual page.  I even do this for 'one-offs' (i.e. a query that is only ever accessed by a single page).  There are multiple reasons for this (ease of modification, scalability, modularity, etc.).  However by far the easiest is simply that it allows you to use queries or anything else for that matter within a <cfscript> block.  Because the form structure is already stored in memory by the server upon posting the form (within that request) it doesn't have any downside that I can see to include any of the scopes to your components.  In fact, although if the component is invoked on the calling page you can see the scopes directly (FORM, URL, SESSION, APPLICATION, SERVER, REQUEST,CGI) it is 'bad practice' to referrence them directly from a component - after all... even though you now are using the local web server - you might in the future be using a different viewer (web services for example).  So any time you wish to pass in a scope you can do so by including it in the arguments (as Plucka correctly has provided an example).  You can do this for any scope... (expanded example follows... please give Plucka the points as that answer is correct).

<cffunction name="getScopedValues" access="public" returntype="struct">
      <cfargument name="argform" required="yes" type="struct" />
                <cfargument name="argurl" required="yes" type="struct" />
                <cfargument name="argsession" required="yes" type="struct" />
                <cfargument name="argapplication" required="yes" type="struct" />
      var ReturnedData = structNew();
                ReturnedData.FormVals = Arguments.argform;
                ReturnedData.UrlVals= Arguments.argurl;
                ReturnedData.SessionVals= Arguments.argsession;
                ReturnedData.ApplicationVals= Arguments.argapplication;
      <cfreturn ReturnedData >

<cfdump var="#getScopedValues(Form,Url,Session,Application)#">

Not particularly useful example since it merely combines the scopes into a single structure and then returns them, but you get the idea.
whaleykAuthor Commented:
Thank you both so much.  As digicidal says, Plucka, you're right so you get the points.  :-)  
digicidal, thank you so much for the valuable explanation.  Learning "why" is as important to me now as making this stuff work. I look forward to learning more from you in the future.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.