# Creating Action Pages

| To create an action page for the form:

1. Create a new application page in Studio.
2. Enter the following code:

       <HTML>
       <HEAD>
       <TITLE>Retrieving Employee Data Based on Criteia from Form</TITLE>
       </HEAD>

       <BODY>
       <CFQUERY NAME="GetEmployees" DATASOURCE="CompanyInfo">
           SELECT FirstName, LastName, Salary
           FROM Employees
           WHERE LastName='#Form.LastName#'
       </CFQUERY>
       <H4>Employee Data Based on Criteria from Form</H4>
       <CFOUTPUT query="GetEmployees">
       #FirstName#
       #LastName#
       #Salary#<BR>
       </CFOUTPUT>
       </BODY>
       </HTML>

3. Save the page as `actionpage.cfm` within the `myapps` directory.
4. View `formpage.cfm` in your browser.
5. Enter data for the LastName form control and submit it.
6. Return to the form in your browser.
7. Reset the values.
8. Do not check the checkbox and submit the form again.

   An error occurs when the checkbox does not pass to the action page.

   You will receive errors if you submit the form without checking the checkbox form controls. You will learn how to apply conditional logic to your action page to compensate for this HTML limitation in "Testing for a variable's existence" on page 51.

### Code Review

Code | Description
--- | ---
    <CFQUERY NAME="GetEmployees"
    DATASOURCE="CompanyInfo">
| Query the datasource CompanyInfo and name the query GetEmployees.
    SELECT FirstName, LastName, Salary
    FROM Employees
    WHERE LastName='#Form.LastName#'
| Retrieve the FirstName, LastName, and Salary fields from the Employees table, but only if the value of the LastName field matches what the user entered in the LastName text box in the form on `formpage.cfm`.
    <CFOUTPUT query="GetEmployees">
| Display results of the GetEmployees query.
    #FirstName#
    #LastName#
    #Salary#<BR>
| Display the value of the FirstName, LastName, and Salary fields for a record, starting with the first record, then go to the next line. Keep displaying the records that match the criteria you specified in the SELECT statement, followed by a line break, until you run out of records
    </CFOUTPUT>
| Close the CFOUTPUT block

## Form Variable Notes and Considerations

When using form variables, keep the following guidelines in mind:

- A form variable's scope is the action page.
- Prefix form variables with "form." when referencing them on the action page.
- Surround variable values with pound signs (#) for output.
- Checkboxes and radio buttons are only passed to the action page if an option is selected.
- Form variables for checkboxes and radio buttons generate errors on action pages if nothing is selected for the form controls.