The Action Page


After the form data is entered and validated, it is pushed to the action page for processing. You can use FORM variables on the action page in much the same way that you would use URL or even local variables. Consider this example:

 <cfquery name="GetEmployees"          datasource="MyDSN"> SELECT * FROM Employees WHERE EmployeeID = #FORM.EmployeeID# </cfquery> 

FORM variable name=value pairs for text boxes, text areas, and drop-down lists always exist on the action page even if the user didn't enter any information. For instance, if a text box named FName was left empty upon form submission, the action page would get FName=.

This point is important because some form controlsnamely checkboxes, radio buttons, multiple select controls, and submit buttons that are not clickedare not passed at all if they are not selected. So if a form has a set of checkboxes named FavColor, and the user doesn't check any of them, nothing is sent to the action page.

It is very important that you do the following on your action page:

  • Set default values for form controls that could potentially not exist by using <cfparam>.

    or

  • Use the IsDefined() function in your conditional statements to perform validation to ensure that a variable exists before you use it.

<cfparam> was introduced in Chapter 2, "Working with Variables and Expressions."


TIP

We've stated before that it is always a good idea to prefix your ColdFusion variables. However, it's OK not to prefix your variables if you want to intentionally leave your code flexible. For instance, consider this example:

 <cfquery name="GetEmployees"          datasource="MyDSN"> SELECT * FROM Employees WHERE EmployeeID = #EmployeeID# </cfquery> 

If this code were in the action page, it could use either a FORM variable or a URL variable in the WHERE statement.




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net