I'm creating a new form and I thought I'd take jQuery's serialize() out for a spin. This is a totally new form so I'm not locked into form field names yet (all greenfield work).
I have the choice of using either data set (watch the equal signs closely there - this output is not a typo) :
data=userId=99&firstName=John&lastName=Doe&interestName=2&interestName=8&sdf&interestName=5 or data=userId=99&firstName=John&lastName=Doe&interestName_1=2&interestName_2=8&sdf&interestName_3=5
My current solution isn't pretty and with the conditional logic will not be easy to maintain. Now that I've explained my looping, here is the fugly code:
<cfoutput>
<cfloop list="#url.data#" index="i" delimiters="&">
<cfset key = listfirst(i,'=')>
<cfset keyValue = listlast(i,'=')>
<cfif key eq 'userId'>
<cfset userId = keyValue>
</cfif>
<cfif key contains 'interestName_'>
<cfquery name="rsInsert" datasource="playground">
insert into table (optionId,userId)
values
(#keyValue#,#userid#)
</cfquery>
</cfif>
</cfloop>
</cfoutput>
What are some options to making this more efficient?