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>
        <cfif #tempAmount# EQ 1>

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)

<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#" />
<input type="hidden" name="shipping" value="#variables.shippingcost#" />
<input style="float:right;" type="image" src="images/proceed_to_checkout.png" value="PayPal" />

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>
<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>
                <cflocation url="ErrorAmount.cfm">
        <cfif session.shoppingcart[i].quantity EQ #tempQuantity#>
                <cfset tempQuantity = 0>
                <cflocation url="ErrorQuantity.cfm">

<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 from="1" to="#arrayLen(session.shoppingcart)#" index="i">
  <cfset totalweight = variables.totalweight + totalitemweight[i]>
<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 FORM.shipping NEQ variables.shippingcost>
  <cflocation url="ErrorShipping.cfm">

<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

Edited by Cheesecake87: n/a

6 Years
Discussion Span
Last Post by jsmall26
<!--- CFPARAM will set and store temp variables in memory. I did this just for the sake of making it work here. --->
<cfparam name="amount_" default="0">
<cfparam name="quantity_" default="0">

<!--- The variable Amount_ is set. This will accept url.amount_ as well. --->
<!--- When You set variables from other variables, dont put them in quotes. Store "hard data" in quote though. --->
<cfset tempAmount = amount_ + "1">

<!--- The variable Amount_ is set. This will accept url.quantity_ as well. --->
<cfset tempQuantity = quantity_ + "1">

<!--- no need for pound signs in the CFIF statement --->
<cfif tempAmount EQ "1">
	Yes - 
	No - 
	  <!--- Added for looks on the page --->
	  <!--- here's your final result, which should be "Yes - 1 1 " --->
<cfoutput>#tempAmount# #tempQuantity#</cfoutput>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.