User Guide

Table Of Contents
Dynamic expressions and dynamic variables 95
3.
Save the file as ShoppingCartAction.cfm
4.
Open ShoppingCartform.cfm in your browser, change the check box and quantity values, and
click Submit.
Reviewing the code
The following table describes the code:
Code Description
<cfif isDefined("Form.submit")>
Run the CFML on this page only if it is called by submitting a
form. This is not needed if there are separate form and
action pages, but is required if the form and action page
were one ColdFusion page.
<cfparam name="Form.itemID"
default="">
Set the default Form.itemID to the empty string. This
prevents ColdFusion from displaying an error if the user
clears all check boxes before submitting the form (so no
product IDs are submitted).
<cfoutput>
You have ordered the following
items:<br>
<br>
<cfloop index="i" list=
"#Form.itemID#">
ProductName:
#Form["product_" & i]#<br>
Product Code:
#Form["sku_" & i]#<br>
Quantity:
#Form["qty_" & i]#<br>
<br>
</cfloop>
</cfoutput>
</cfif>
Display the name, SKU number, and quantity for each
ordered item.
The form page posts Form.itemID as a list containing the
value attributes of all the check boxes. These attributes
contain the shopping cart item IDs for the selected cart
items. Use the list values to index a loop that outputs each
ordered item.
Use associative array notation to access the Form scope as
a structure and use expressions in the array indexes to
construct the form variable names. The expressions consist
of a string containing the field name’s field type prefix (for
example, "sku_"), concatenated with the variable i, which
contains the shopping cart ItemID number (which is also the
loop index variable).