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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling dynamic form fields

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
This concept always eludes me.

I have a form on which the the fields are dynamically created. All three of the form fields below will have different values for each instance of the loop.
Like this:
Code:
<form name="frm_page" method="post" action="page_5.cfm">
<cfloop query="get_config_options">
  <input type="radio" name="config_opt" value="#get_config_options.config_id#" />
  <input type="hidden" name="total_monthly" value="#total_monthly_fee#" />
  <input type="hidden" name="total_one_time" value="#total_one_time_fee#" />
</cfloop>

Now, on the action page, I need to know the values of the two hidden fields total_monthly & total_one_time...but ONLY the values that are part of the same loop row of whichever radio button is selected. As things are now, when submitted, all values are passed.
My code looks like this:
Code:
<cfif isDefined('form.total_monthly')><cfset page.total_monthly = form.total_monthly></cfif>
<cfif isDefined('form.total_one_time')><cfset page.total_one_time = form.total_one_time></cfif>
...but it just sends the whole comma delimited list of field values.

How can I evaluate the list of submitted field values to only use the one I need? Or better yet, what is the best way to handle this?

Please help, I've been staring at this for 2 hours!
 
You need to have a unique ID in the name of each form field, something that ties the group of fields together but seperates them from the other groups. You will also need to capture a list of all of the IDs used, so you can loop through that list on the action page.
Code:
<input type="hidden" name="ID_List" value="#ValueList(get_config_options.config_id)#>
<cfloop query="get_config_options">
  <input type="radio" name="config_opt_#get_config_options.config_id#" value="#get_config_options.config_id#" />
  <input type="hidden" name="total_monthly_#get_config_options.config_id#" value="#total_monthly_fee#" />
  <input type="hidden" name="total_one_time_#get_config_options.config_id#" value="#total_one_time_fee#" />
</cfloop>
Action Page:
Code:
<cfloop index="i" list="#Form.ID_List#">
<cfif isDefined('form.total_monthly_#i#')>
  <cfset page.total_monthly = form["total_monthly_#i#"]>
</cfif>
...etc...
</cfloop>

Hope This Helps!

ECAR
ECAR Technologies, LLC

"My work is a game, a very serious game." - M.C. Escher
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top