Hi Adrian, Warrick and Ralph,

Thanks for your help. I completed the application yesterday. Here is part of
the code that could be of use to someone else.

Page 1 - Form
---------
<form action="Add_action.cfm" method="post" name="Add">
<table align="center">
<cfset LineNumber=0>
<cfoutput query="Locations">
<tr>
        <td><cfset LineNumber=#LineNumber# + 1>
                <input type="text" name="Location#LineNumber#"
value="#trim(Corporate_Cities.LocationID)#" size="5">
        </td>
        <td><input type="text" name="Rented#LineNumber#" size="5">
                <input type="hidden" name="Rented#LineNumber#_integer"
value="Number of vehicles rented must be a valid Integer value">
        </td>
        <td><input type="text" name="Sitting#LineNumber#" size="5">
                <input type="hidden" name="Sitting#LineNumber#_integer"
value="Number of vehicles sitting must be a valid Integer value">
        </td>
        <td><input type="text" name="Fleet#LineNumber#" size="5">
                <input type="hidden" name="Fleet#LineNumber#_integer"
value="Number of vehicles sitting must be a valid Integer value">
        </td>
        <td><textarea cols="20" rows="1"
name="Comments#LineNumber#"></textarea>
        </td>
</tr>
</cfoutput>
<tr>
        <td colspan="5"><div align="center"><input type="Submit"
value="Submit">&nbsp;&nbsp;<input type="Reset"></div><br></td>
</tr>


Page 2 - Process the Form

<!--- Loop through each row of data entered in the form by appending the row
number to field names and evaluating them for their value. If the field has
been left blank, assign a default value of zero. Insert the row into the
database. --->
<cfloop index="row" FROM="1" TO="#Form.TotalRows#">
        <cfset LocationTemp = "Form.Location" & #row#>
        <cfset Location = #Evaluate("#LocationTemp#")#>
        <cfset RentedTemp = "Form.Rented" & #row#>
        <cfset Rented = #evaluate("#RentedTemp#")#>
                <cfif trim(Rented) eq "">
                        <cfset Rented = 0>
                </cfif>
        <cfset SittingTemp = "Form.Sitting" & #row#>
        <cfset Sitting = #evaluate("#SittingTemp#")#>
                <cfif trim(Sitting) eq "">
                        <cfset Sitting = 0>
                </cfif>
        <cfset FleetTemp = "Form.Fleet" & #row#>
        <cfset Fleet = #evaluate("#FleetTemp#")#>
                <cfif trim(Fleet) eq "">
                        <cfset Fleet = 0>
                </cfif>
        <cfset CommentsTemp = "Form.Comments" & #row#>
        <cfset Comments = #evaluate("#CommentsTemp#")#>
                
<cfoutput>

<tr>
        <td>#location#</td>     
        <td>#Rented#</td>       
        <td>#Sitting#</td>      
        <td>#Fleet#</td>        
        <td>#Comments#</td>     
</tr>

</cfoutput>

        <cfset SubmitDate=Now()>
        <cfparam name="Form.LongWeekend" default="0">
                
<!--- Insert the data entered on previous two pages to the Database --->
<cfquery datasource="query">
        INSERT INTO Table ( Field1,..... )      VALUES (value1,...)
</cfquery>
</cfloop>


Original question:

I am trying to make a small data entry screen in ColdFusion. There are five
columns in the table. Number of rows is dynamically generated with the first
column automatically filled in. Others have to be filled in by a user. When
the user submits the form, each row is inserted in a database as a new row.

I have not done a form submission until now that updates multiple rows. I
hope you can help me with the basic logic involved in this. My guess would
be to insert the data from the form into a 2 dimensional Array and then loop
over the array while inserting into the database. How do I insert it into an
array and proceed from there?

CH1             CH2             CH3             CH4             CH5
----------------------------------------------------------------------------
---------
Field1          Field2          Field3          Field4          Field5
Field1          Field2          Field3          Field4          Field5
Field1          Field2          Field3          Field4          Field5



Dharmesh Goel
Programmer Analyst
IT Dept. - Discount Car & Truck Rentals
416-744-0123 x290

------------------------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists or send a message 
with 'unsubscribe' in the body to [EMAIL PROTECTED]

Reply via email to