Using Decision Functions to Build Expressions

Use decision functions to test for the presence of ColdFusion elements such as form variables, queries, and their simple values so that you can perform conditional processing.

When you use decision functions:

The table below describes the most frequently used decision functions.

Refer to the CFML Language Reference for ColdFusion Express for a complete listing.

Function Usage
IsDefined Tests if a variable by a specific name exists.
IsDebugMode Tests if debugging is enabled on the page.
IsDate Tests if a variable value is time-date.
IsNumeric Tests if a variable value is numeric.
IsQuery Tests if a variable contains query data.
IsStruct Tests if a variable contains structure data.

Usage example

Checkbox and radio button form variables only pass to action pages when an option is enabled on the form.

The code below is added to a form's action page to check for the existence of a checkbox variable.

<CFIF IsDefined("Form.Contract") IS "YES">
    Status: Contract Employee
<CFELSE>
    Status: Permanent Employee
</CFIF>

During the next procedure, use this expression syntax on your action page to check for the existence of a checkbox before trying to process it.

Note To test for a variable's existence:
  1. Open ActionPage.cfm in HomeSite.
  2. Title the page Chapter 8 Action Page.
  3. Delete the line Contract Status: #Form.Contract#<BR> within the CFOUTPUT block.
  4. You will replace it with new code as you go.

  5. Add an opening CFIF tag immediately after the ending CFOUTPUT tag to test if #Form.Contract# is defined:
  6. <CFIF IsDefined("Form.Contract") IS "YES">
    
  7. Add a true procedure after the tag to output a label and a value:
  8. Status: Contract Employee
    
  9. Add a CFELSE tag.
  10. Add a false procedure after this tag to output a label and a value:
  11. Status: Permanent Employee
    
  12. Add an ending CFIF to end the conditional logic statement.
  13. Your output block should look like this:
  14. <CFIF IsDefined("Form.Contract") IS "YES">
        Status: Contract Employee
        <CFELSE>
        Status: Permanent Employee
    </CFIF>
    
  15. Save the page.
  16. View FormPage.cfm in a browser.
  17. Fill out each field and submit the form.
  18. ActionPage.cfm should return all the values that you entered on the form.

    The status field should appear as Contract Employee.

    If you receive errors, read the error message and check for spelling mistakes on the action page.

  19. Return to the form in the browser.
  20. Reset the form.
  21. Do not check the checkbox and submit the form again.
  22. The status field should appear as Pemanent Employee.

Click here to see what results you should get.

Click here to see the new code on the action page.

Move on in this chapter to learn how to use operators to perform conditional logic testing.