Processing form data

Virtually all web applications that gather and write information to a database use a form to accomplish that task. Forms let you collect information from a user (using an order form, registration form, and so on) and write that information to a database. Like HTML, there are two independent steps for creating a form in ColdFusion:

  1. Creating the layout for the form itself.
  2. Writing the code to process the submitted information.

Form processing

Every form that you create in ColdFusion consist of two parts: the form page and the action page.These two pages work together to process user input. The form page contains the user interface elements, such as input fields, and radio buttons. The action page handles the processing of the form page data.

When a user submits a form, the form values are stored in form variables and sent to the action page for processing. The following figure shows the relationship between the form page and action page:

This image shows the relationship between the form page and action page.

In order for the form page to find its corresponding action page, the action statement in the form tag must be correct. The form tag includes the information that tells the server where to send the data that it collects. It also tells the server how to send it. To processes these instructions to the server, the form tag uses the following syntax:

<form action="actionpagename.cfm" method="Post">
  HTML and CFML form tags
</form>

The first attribute (action) in the form tag lets you specify where to send the data. The page that you specify where to send the data is the name of the action page. The second attribute in the form tag is method. The only method that ColdFusion supports is post. All ColdFusion forms must set the method attribute to post.

In Part II of this book, you will use ColdFusion form tags to create forms and write collected values to a database.

Comments