I am having a problem looping out a value from posted data into a loop, heres some code:
<cfset tempAmount = "URL.amount_" & 1>
<cfset tempQuantity = "URL.quantity_" & 1>
<cfoutput>
<cfif #tempAmount# EQ 1>
Yes
<cfelse>
no
</cfif>
#tempAmount##tempQuantity#
</cfoutput>
That is a small test section I have been playing around with to try and get it working, but you can see what I am trying to do.
I am passing values that have been outputed from a loop into form variables, the number of form variables being passed can vary. The main objective of this code is to cross check the data being sent from the form.
Here is my full code:
Shopping Cart: (this outputs the shopping cart info into a form)
<cfoutput>
<form action="checkout.cfm" name="Formcart" method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="MyEmail" />
<cfloop from="1" to="#arrayLen(session.shoppingcart)#" index="i">
<input type="hidden" name="item_name_#i#" value="#session.shoppingcart[i].name#" />
<input type="hidden" name="amount_#i#" value="#session.shoppingcart[i].price#" />
<input type="hidden" name="quantity_#i#" value="#session.shoppingcart[i].quantity#" />
</cfloop>
<input type="hidden" name="shipping" value="#variables.shippingcost#" />
<input style="float:right;" type="image" src="images/proceed_to_checkout.png" value="PayPal" />
</form>
</cfoutput>
Checkout: this cross checks the data being sent from the form, and if everything is good it will pass the data onto paypal.(in theory)
<cfset totalItems = 0>
<cfloop from="1" to="#arrayLen(session.shoppingcart)#" index="i">
<cfset totalItems = variables.totalItems + session.shoppingcart[i].quantity>
</cfloop>
<cfparam name="tempAmount" default="0">
<cfparam name="tempQuantity" default="0">
<cfloop from="1" to="#arrayLen(session.shoppingcart)#" index="i">
<cfset tempAmount = "FORM.amount_" & i>
<cfset tempQuantity = "FORM.quantity_" & i>
<cfif session.shoppingcart[i].price EQ #tempAmount#>
<cfset tempAmount = 0>
<cfelse>
<cflocation url="ErrorAmount.cfm">
</cfif>
<cfif session.shoppingcart[i].quantity EQ #tempQuantity#>
<cfset tempQuantity = 0>
<cfelse>
<cflocation url="ErrorQuantity.cfm">
</cfif>
</cfloop>
<cfparam name="totalweight" default="0">
<cfloop from="1" to="#arrayLen(session.shoppingcart)#" index="i">
<cfset totalitemweight[i] = session.shoppingcart[i].weight * session.shoppingcart[i].quantity>
</cfloop>
<cfloop from="1" to="#arrayLen(session.shoppingcart)#" index="i">
<cfset totalweight = variables.totalweight + totalitemweight[i]>
</cfloop>
<cfparam name="shippingcost" default="0">
<cfif totalweight LT 2>
<cfset shippingcost = 4.41>
<cfelseif totalweight GTE 2 AND totalweight LT 4>
<cfset shippingcost = 7.06>
<cfelseif totalweight GTE 4 AND totalweight LT 6>
<cfset shippingcost = 9.58>
<cfelseif totalweight GTE 6 AND totalweight LT 8>
<cfset shippingcost = 11.74>
<cfelseif totalweight GTE 8 AND totalweight LT 10>
<cfset shippingcost = 12.61>
<cfelseif totalweight GTE 10 AND totalweight LT 20>
<cfset shippingcost = 14.69>
</cfif>
<cfif FORM.shipping NEQ variables.shippingcost>
<cflocation url="ErrorShipping.cfm">
</cfif>
<cflocation url="https://www.paypal.com/cgi-bin/webscr?#CGI.QUERY_STRING#" >
What I am having a problem with is joining the "form.whatever_" with the index'd number to output "form.whatever_1" , then using this output to check its value.(Go to the top test code for the example of this)
Thanks for the help in advance :P