Building multi-step forms
Posted by Rahul
We at most of the times are required to build multi-step forms, involving passing on the form data from 1 page to the other.
I generally use this small UDF to include the form elements from the previous page. It also has the argument which can be used to exclude certain fields to be omitted. All the form fields except the special "fieldnames" and the one's in the exclude list will be passed as hidden fields to the next page. Here is the UDF code
<cffunction name="createHiddenFields" output="no" returntype="string">
<cfargument name="excludeFields" type="string" default=""/>
<cfscript>
var formFieldsList ="";
var formFieldArray= ArrayNew(1);
var formHTML="";
var element=0;
var exclude = listappend(arguments.excludeFields,"formfields");
if(structKeyExists(form,"fieldnames")) {
formFieldsList = form.fieldnames;
}
formFieldArray = listtoArray(formFieldsList);
</cfscript>
<cfsavecontent variable="formHTML">
<cfoutput>
<cfloop from ="1" to="#ArrayLen(formFieldArray)#" index="element">
<cfif listfindnocase(exclude,formFieldArray[element]) eq 0>
<input type="hidden" name="#lcase(formFieldArray[element])#" value="#htmleditformat(form[formFieldArray[element]])#">
</cfif>
</cfloop>
</cfoutput>
</cfsavecontent>
<cfreturn formHTML />
</cffunction>
To use the UDF just call this udf anywhere within the <form>...</form> in your page
You might also find similar functionality implemented as a custom tag on dans.blog

