How do I create a multi-page form?
A multi-page form is really a series of forms linked together and passing information from one to the next. There are many ways to implement this, and we'll present one here. We will create each page of the form as a separate ColdFusion file, while using a controller file (that displays nothing) to decide which page to display when. The key to understanding the process in TerraForm is to grasp that the form provides its own validation, so each form page must in a way "catch" its own submission. Once each page has been validated, the controller will request the next page of the form.
cnt_multipageform.cfm looks like this:
<cfparam name="form.step" default="1"> <cfinclude template="frm_Page#form.step#.cfm"> <cfif Form.MultiPageForm EQ "Valid"> <cfif form.step eq 3> <!--- process the form ---> <cfinclude template="act_MultiPageForm.cfm"> <cflocation URL="MultiPage_Form_thanks.cfm"> <cfelse> <!--- move to the next page ---> <cfset form.step = form.step + 1> <cfset Form.MultiPageForm = "new"> <cfinclude template="frm_Page#form.step#.cfm"> </cfif> </cfif>
And this is what would happen:
frm_page1.cfm- page 1 displays.
- User submits page 1.
frm_page1.cfm- page 1 is validated.
- If page 1 fails, it is re-displayed, otherwise
form.stepis incremented and page 2 is included.
- User submits page 2.
frm_page2.cfm- page 2 is validated.
- If page 2 fails, it is re-displayed, otherwise
form.stepis incremented and page 3 is included.
- User submits page 3.
frm_page3.cfm- page 3 is validated.
- If page 3 fails, it is re-displayed, otherwise the form is processed (
act_MultiPageForm.cfm) and the browser is redirected to a thanks page.
While this is happening, each form must remember to pass on the values from the previous form. TerraForm helps here with the
passthroughfieldlist attribute. Use this attribute in your
<cf_terraform> tag to list all the fields from the previous pages, for example:
A sample is available for download in the Code Gallery.