As was mentioned before, you could set parameters to make sure you have all
the form fields on the action page. What is the mechanism by which you
determine how many option groups are on the form? I'm assumiing it's
something dynamic based on the user using the form. If it is, then I'd use
whatever that same mechanism is on the action page to set your params. Or,
if it's just a matter of the number of options, pass that as a hidden field
and loop through it like so:

<cfloop from="1" to="#formCount#" index="i">
  <cfif isDefined("form.option#i#")>
                <cfquery datasource="#request.dsn#">
                 INSERT cart_options (optionID, cartLineID)
                 VALUES ('#Evaluate("form.option#i#")#', #LastID#)
                </cfquery>
  </cfif>
        </cfloop>


On 2/8/06, j s <[EMAIL PROTECTED]> wrote:
>
> I was able to figure out how to do the multi insert.  Here are the steps I
> took.
>
> To make sure the form values where passed I setup an actionpage.cfminstead of 
> going directly to a cfc.  On the top of the page I added <cfdump
> var="#form#" label="Form variables" />.
>
> Once I knew extactly what formfields where passed I created a variable to
> hold the number of mulitple fields for insert.
>
> <cfset formCount = ListLen('#FORM.FieldNames#', ",")>
>
> <!--- minus hidden and other fields that are not part of the multi insert
> -->
>         <cfset formCount = formCount - 4>
>
> <!--- Query to insert into the fist table.  These values are not part of
> the multi insert. --->
>
> <cftransaction>
>         <cfquery datasource="#request.dsn#">
>                 INSERT INTO cart (cart_custcart_ID, productID, qty,
> cart_dateadded)
>                 VALUES ('#Client.CartID#',#FORM.productid# ,#FORM.qty#
> ,#CreateODBCDateTime(Now())#)
>         </cfquery>
>
> <!--- Get the last id for use in the multi insert --->
>
>         <cfquery name="lastRec" datasource="#request.dsn#">
>                 SELECT LAST_INSERT_ID() as lastid
>         </cfquery>
>
> <!--- I set the lastID cause without it I get an error message --->
>         <cfset lastID = lastRec.lastid>
>
> <!--- Here is where the multi insert is done. The formCount is used to
> setup loop for the Options --->
>
>         <cfloop from="1" to="#formCount#" index="i">
>                 <cfquery datasource="#request.dsn#">
>                  INSERT cart_options (optionID, cartLineID)
>                  VALUES ('#Evaluate("form.option#i#")#', #LastID#)
>                 </cfquery>
>         </cfloop>
> </cftransaction>
>
> I still have a problem I hope someone can answer.  On the form if their
> are 3 options to select from (radio buttons) and I select option 1 and 3, I
> get an error message because the options are not concurrent .  This is
> because the loop goes thru 2 options; option1 and option2 instead of option1
> and option3 and gives an error stating their is no value for option2.  Any
> ideas?
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:231717
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to