Skip to content

Instantly share code, notes, and snippets.

@nastanford
Last active December 19, 2015 01:49
Show Gist options
  • Save nastanford/5878509 to your computer and use it in GitHub Desktop.
Save nastanford/5878509 to your computer and use it in GitHub Desktop.
Loop through form fields
<cfloop index="thefield" list="#form.fieldnames#">
<cfset fields="#thefield# = #form[thefield]#">
<cfset fields="#thefield# = #evaluate(thefield)#">
<cfoutput>#fields#</cfoutput><br>
</cfloop>
Example making the form fields into hidden Form Fields
<!--- ********************************************** --->
<cfloop index="thefield" list="#form.fieldnames#">
<input type="hidden" name="#thefield#" value="#form[thefield]#" />
<input type="hidden" name="#thefield#" value="#evaluate(thefield)#" />
</cfloop>
Example making the form fields into session Fields
<!--- ********************************************** --->
<cfloop index="thefield" list="#form.fieldnames#">
<cfset session.#thefield# = "#form[thefield]#">
<cfset session.#thefield# = "#evaluate(thefield)#">
</cfloop>
<cfscript>
component displayname="User Defined Functions" hint="User Defined Functions" output="true"
{
// Hidden Form Fields Function
public string function formFields(_form)
{
var _results ="";
savecontent variable="_results"
{
for(i=1;i<=ListLen(_form);i++){
if(ListGetAt(_form,i) neq ""){
writeOutput("<input type='hidden' name='"&ListGetAt(_form,i)&"' value='"&form[ListGetAt(_form,i)]&"'>");
}
}
}
return _results;
}
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment