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

Using loop to pass form fields and values 1

Status
Not open for further replies.

evergreean43

Technical User
May 25, 2006
165
US
I have a action page that works where I am passing alot of form values. The below example is a condense version of all my form values:
Code:
<cfoutput>
<form action="goto.cfm" method="post">
<input type="hidden" name="city" value="#form.city#">
<input type="hidden" name="state" value="#form.state#">
<input type="hidden" name="county" value="#form.county#">
<input type="hidden" name="section" value="#form.section#">
</form>


I would like to do this a more efficient way such as putting the form fields and values into a loop but not sure how do to it correctly. Please advise how I can make the loop below work?

Code:
<cfset myvar = "">
<cfloop list="#form.fieldnames#" index="i">
<cfif len(trim(i)) gt 0>
  <!--- put #i# here or what?  --->
</cfif>
</cfloop>
<form action="goto.cfm" method="post">
  <!--- not sure if this is in the right direction?  --->
<input type="hidden" name="myvar" value="#i#">
</form>
</cfoutput>

 
Try this, it should be all you need:
Code:
<form action="goto.cfm" method="post">
<cfoutput>
    <cfloop list="#form.fieldnames#" index="f">
        <input type="hidden" value="#FORM[f]#" name="#f#">
    </cfloop>
<cfoutput>

Hope This Helps!

ECAR
ECAR Technologies

"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