For Adobe ColdFusion application servers 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.

The controller 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">
    <!--- move to the next page --->
    <cfset form.step = form.step + 1>
    <cfset Form.MultiPageForm = "new">
    <cfinclude template="frm_Page#form.step#.cfm">


And this is what would happen:

  1. Include frm_page1.cfm - page 1 displays.
  2. User submits page 1.
  3. Include frm_page1.cfm - page 1 is validated.
  4. If page 1 fails, it is re-displayed, otherwise form.step is incremented and page 2 is included.
  5. User submits page 2.
  6. Include frm_page2.cfm - page 2 is validated.
  7. If page 2 fails, it is re-displayed, otherwise form.step is incremented and page 3 is included.
  8. User submits page 3.
  9. Include frm_page3.cfm - page 3 is validated.
  10. 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.

Uniform Resource Locator
No comments yet