Sending Form Data to Funtion as Structure without knowing all form names

Hi I am doing a loop like this over my form fields:

<cfoutput query="data">
	<label><span>#data.description#</span></label>
    <textarea name="#data.name#" id="#data.name#" rows="10" class="textareas" cols="50">#data.html_body#</textarea>
</cfoutput>

Open in new window


now it can contain 5 or 10 or 20 fields depending upon what is coming from the database

i now need to loop over the form structure and update the procedure so the correct value should get updated ,

my code for procedure is;

I am trying like this, but not sure, it is correct or not

<cfset lsterrors = "">	
	<cfloop list="#structKeyList(structform)#" index="key">	
	<cfstoredproc procedure="sp_gs_mailtemplates_update" datasource="#Application.ds#">
		<cfprocparam cfsqltype="CF_SQL_VARCHAR" value="#key#">
		<cfprocparam cfsqltype="CF_SQL_VARCHAR" value="#testStruct[key]#"> -  This seems to be incorrect
		<cfprocresult name="returncode">
	</cfstoredproc>
	<cfset lsterors = listAppend(lsterrors,returncode,',')>
	</cfloop>

Open in new window

LVL 16
Gurpreet Singh RandhawaCEOAsked:
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.

gdemariaCommented:
Don't you want to call your procedure only once with all the form fields?   Currently, you are looping around your procedure so you are calling it once for every field?

You could call it once and pass it the entire form structure...   <cfset errors = sp_gs_mailtemplates_update(form)>
0
gdemariaCommented:
but to answer your question about your code, you have testStruct when it seems you should have structform

<cfloop list="#structKeyList(structform)#" index="key">	
	<cfstoredproc procedure="sp_gs_mailtemplates_update" datasource="#Application.ds#">
		<cfprocparam cfsqltype="CF_SQL_VARCHAR" value="#key#">
		<cfprocparam cfsqltype="CF_SQL_VARCHAR" value="#structform[key]#"> ---  changet his to structForm
		<cfprocresult name="returncode">
	</cfstoredproc>
	<cfset lsterors = listAppend(lsterrors,returncode,',')>
	</cfloop>

Open in new window

0

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
Gurpreet Singh RandhawaCEOAuthor Commented:
need to run seperate because for n fields, if 1 failed it should rollback all andsays an error, something else went wrong, if u have better idea, let me know

like update the remaining which are good and rollback entry for the one which failed
0
gdemariaCommented:
Ok, so did that fix work for you?
0
Gurpreet Singh RandhawaCEOAuthor Commented:
yes it worked
0
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
ColdFusion Language

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.