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.
-
Add a newsfeed to your site
Use the Moreover news service to add a news
feed to your site using cfhttp and wddx in 5 minutes!
Author: Nathan Miller
Views: 20,891
Posted Date: Saturday, July 26, 2003
-
Advanced Server-Side FORM Validation
An advanced set of customizable tags for validating FORM values on the Server-side using User-Defined Functions
Author: Nathan Miller
Views: 17,611
Posted Date: Monday, December 15, 2003
-
Automatically build a FORM using SQL Server system tables
Use SQL server's system tables to automatically create a form to insert data into your database.
Author: Nathan Miller
Views: 20,569
Posted Date: Monday, May 19, 2003
-
ColdFusion Content Injection
Inject customized content into predefined messages by adding specially formatted placeholders in the message.
Author: Nathan Miller
Views: 6,636
Posted Date: Wednesday, March 28, 2007
-
Coldfusion Master Pages
Use ASP.NET-style master pages to replace your header/footer files for web page layout
Author: Nathan Miller
Views: 8,834
Posted Date: Wednesday, August 30, 2006
-
DHTML Tabs (Part 1 of 2)
Visual tab control generator - Creates an interface that loads all the data in each tab in a single page request. This allows the users to click on each tab in the interface and instantly see the data on that tab without waiting for it to load.
Author: Nathan Miller
Views: 8,638
Posted Date: Wednesday, October 26, 2005
-
Dynamically add and remove a 'please wait' message to your complex pages
You can use a combination of and javascript to show a message on the screen
while processing a large data set (or any other long-running task), and then remove the message when the task is complete.
Author: Nathan Miller
Views: 27,370
Posted Date: Tuesday, January 13, 2004
-
Easy automatic debugging
Extend the use of the new tag in CF5
to display any and all ColdFusion and CGI variables.
Author: Nathan Miller
Views: 11,912
Posted Date: Saturday, December 21, 2002
-
Pass complex data in a hidden form field with Base64
Use Base64 to pass html or large blocks of text in a form post without using session variables.
Author: Nathan Miller
Views: 7,682
Posted Date: Friday, March 31, 2006
-
Scope your variables
Increase performace and readability by always scoping your variables
Author: Nathan Miller
Views: 18,014
Posted Date: Monday, May 19, 2003
-
The better way to handle session variables
You can use these simple loops in place of many lines of code to clear out or delete session variables
Author: Nathan Miller
Views: 19,541
Posted Date: Monday, May 19, 2003