This looks like it would be very easily broken.  For example, if your form
looked something like:

<form action="t2.cfm" method="post">
  <input type="checkbox" name="ao_order" value="100">Item #100
  Qty:<input type="text" name="ao_quant"><br>

  <input type="checkbox" name="ao_order" value="101">Item #101
  Qty:<input type="text" name="ao_quant"><br>

  <input type="checkbox" name="ao_order" value="102">Item #103
  Qty:<input type="text" name="ao_quant"><br>

  <input type="checkbox" name="ao_order" value="103">Item #104
  Qty:<input type="text" name="ao_quant"><br>

  <input type="submit" value="Add to Shopping Cart">
</form>

Say someone checks off items 100 and 104, but enters quantities for items
100, 101, and 104.  Your lists won't be the same length and the second
quantity in the AO_QUANT list won't be the ordered quantity for item 104.

In fact, I doubt that any HTML standard spells out the browser behavior when
you have multiple text fields submitted with the same name.  That is,
there's no gaurantee the AO_QUANT list that the browser submits would be in
any particular order.  Even if you find all browsers behave in the same
manner, changing the layout of the page could potentially change that order.

A better approach would be to tag the the quantity fields with the item
number, as in

<input type="text" name="ao_quant_100">
<input type="text" name="ao_quant_101">
<input type="text" name="ao_quant_102">

In your loop, look to see if the quantity form field is defined (for safety
sake), then evaluate the field name to get it's value.

<cfparam name="form.ao_order" default="">
<cfloop index="item" list="#form.ao_order#">
  <cfif IsDefined("form.ao_quant_#item#")>
    <cfset quantity = Val(Evaluate("form.ao_quant_#item#"))>
    <cfif quantity neq 0>
      <cfquery name="ORDERS" datasource="AO_LITERATURE">
      INSERT INTO PRODUCT_ORDERS (ORDER_ID, AO_ORDER, AO_QUANT)
      VALUES ('#CLIENT_ID#', '#item#', '#quantity#')>
      </CFQUERY>
    </cfif>
  </cfif>
</cfloop>


Jim

----- Original Message -----
From: "Les Mizzell" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Thursday, March 08, 2001 10:07 PM
Subject: Re: <CFLOOP> Question/Problem


>
> > |<cfset list1 = "1,2,3,4">
> > |<cfset list2 = "mom,pop,dad,sis">
> > |
> > |<cfset counter = 1>
> > |<cfloop index="qty" list="#list1#">
> > | <cfoutput>
> > | Counter = #counter# Qty = #qty#
> > |list2 = #ListGetAt(list2, counter)#<br>
> > | </cfoutput>
> > | <cfset counter = counter + 1>
> > |</cfloop>
>
> Yea, I believe a modification of that would work for me.  I suppose I
could
> put an CFIF in there to check and be sure there wasn't a zero value in on
> side of the pair, and if there was, just don't write that one to the
> database.
>
> This is a huge form that was completely designed BEFORE I even knew it was
> being done. THEN they said, "Here you go, make it so folks can order this
> stuff." Check boxes and everything in place. Pure HTML.  Could have
> data-driven the thing and been done already, but there's not really any
way
> to match the weird layout there. That's what you get when the client
starts
> designing parts of the site himself I suppose.
>
> Thanks!
>
> --
> Les Mizzell
> ****************
> Who Needs Intel?
> ATHLON INSIDE!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to