Scope your variables

ColdFusion has many different scopes for variables. Some of the major ones include Application, session, client, 
variables, request, cookie, FORM, URL, and there are others.

When setting and reading variables, you should always prefix the variable name with the appropriate scope.

For example, if you submit a form with a 'name' field, the action page will have access to that variable
as either 'name' or 'FORM.name'.

It isn't necessary to supply the 'FORM' part of the variable name, but there are three reasons you should.

1. It is a best practice - you should just do it!

2. It is easier to read - Requirements tend to grow larger and more complex, and your pages will need additional code to handle the increased complexity. If your variables aren't scoped, you can lose site of where the variable comes form.

3. The page will run faster - If all variables are scoped, the CF server knows where to look for the variable when reading them. If your variables don't have a scope, the server has to look around in memory until it finds it.

These rules apply to all scopes, not just FORM variables.



All ColdFusion Tutorials By Author: Nathan Miller