Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass dynamically generated form names

Status
Not open for further replies.

phylum1234

Programmer
May 13, 2007
2
US
I'm trying to pass dynamically generated form names and their values to an update query. I've tried to pass the form name query which gives me the form names in the first

place, but then I have to somehow piece together "form." and the dynamically generated name, which in this case is a unique ID from the database to the update query fields

form page:

<cfform action="updateRateAction.cfm" method="post" name="yearView">
<cfoutput query="getRates">
<tr>
<td><A HREF="deleteRate.cfm?rate=#getRates.ID#&comp=#comp#&year=#year#">d</A> / <A HREF="updateRate.cfm?rate=#getRates.ID#&comp=#comp#&year=#year#">u</A>
</td>
<td>#cat_num#</A></td>
<td width="325"><span class="11"><strong>#labor_cat#</A> </strong></span></td>
<td><cfinput name="#getRates.ID#" type="text" value="#DollarFormat(baseOffSite)#" size="6" maxlength="6"></td>
<td><cfinput name="#getRates.ID#" type="text" value="#DollarFormat(baseOnSite)#" size="6" maxlength="6"></td></tr>
more...

update action page:

<cfloop index="i" from="1" to="#ArrayLen(session.rateOffSiteArray)#" step="1">
<cfquery name="updateRates" datasource="rates" dbtype="ODBC">
update laborRates set
baseOffSite = #form. (...this where I'm having trouble...)#
where ID = #session.rateOnSiteArray#
</cfquery>
</cfloop>
</cfoutput>
 
There are two ways you can do it. One is two keep a list of the ID values used in the form, then pass them as a list to the form action page.
Code:
<cfform action="updateRateAction.cfm" method="post" name="yearView">
[red]<input type="hidden" name="ItemList" value="<cfoutput>#ValueList(getRates.ID)#</cfoutput>">[/red]
<cfoutput query="getRates">
<tr>
....
<td><cfinput name="#getRates.ID#" type="text" value="#DollarFormat(baseOffSite)#" size="6" maxlength="6"></td>
<td><cfinput name="#getRates.ID#" type="text" value="#DollarFormat(baseOnSite)#" size="6" maxlength="6"></td></tr>
more...   


ACTION PAGE

<cfloop index="i" list="[red]#Form.ItemList#[/red]">
  <cfquery name="updateRates" datasource="rates" dbtype="ODBC">
  update laborRates set baseOffSite = #form[i]#
  ...blah, blah, blah...
  </cfquery>
</cfloop>

The second way would just be to dynamically loop through all form fields passed to the action page.
Code:
...No changes to Form Page...

ACTION PAGE

<cfloop list="#form.fieldnames#" index="i">
  <cfquery name="updateRates" datasource="rates" dbtype="ODBC">
  update laborRates set baseOffSite = #form[i]#
  ...blah, blah, blah...
  </cfquery>
</cfloop>

While I doubt any of this is "copy and paste" code, it should give the general idea as to what you need to do.


Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Another way is to name the fields consecutively:

baseOffSite1,
baseOffSite2,
..

Code:
form page:
<cfoutput>
<input type="hidden" name="numberOfRates" value="#getRates.recordCount#">
</cfoutput>

<cfoutput query="getRates">
   ...
   <cfinput name="baseOffSite#currentrow#"  ...>
</cfoutput>
 
update action page:

....
<cfloop from="1" to="#form.numberOfRates#" index="counter">
<cfquery ..>
     Update laborRates 
     Set baseOffSite = #form["baseOffSite"& counter]#
     Where ...
</cfquery>
</cfloop>
...
 
That works fine, as long as all of the ID's are in consecutive order starting with 1. But what happens if they're not? What happens if the form page only has 3 ID's, and they are between 1 and 574?


Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
ECAR,

Doh! I accidently left out the most important part (the ID!) Let's try this again.

Code:
form page:
<cfoutput>
<input type="hidden" name="numberOfRates" value="#getRates.recordCount#">
</cfoutput>

<cfoutput query="getRates">
   ...
   <cfinput name="baseOffSite#currentrow#"  ...>
   <cfinput name="ID#currentrow#"  ...>
</cfoutput>
 
update action page:

....
<cfloop from="1" to="#form.numberOfRates#" index="counter">
<cfquery ..>
     Update laborRates
     Set baseOffSite = #form["baseOffSite"& counter]#
     Where ID = #form["ID"& counter]#
</cfquery>
</cfloop>
...
 
Actually,Cold Fusion Developers have already solved this problem for me. It may not be the most elegant solution but CFGRID does exactly what I was trying to accomplish in the fist place.

It basically draws the data (even non sequential ID's) and easily updates over the "grid" using the gridupdate tag.

Thanks for all of your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top