Hi again,
Okay now I have a Coldfusion question, I have written a user defined function in coldfusion:

<cfscript>
function isSqlInjection(str) {
  ....
 } 
</cfscript>

Now I am a complete newbie to coldfusion and don't want to have to include this function in every page when I have to do this validation, but would rather have this as a global function to the whole application.
I've inherited this project so not completely 100% on how this application is set up, but if I can get an idea where to place this code to make it global that would be great.

I noticed an _app.cfm file that had some default values assigned and tried placing the function in this file, but that did not work.

Ah nevermind I found the Application.cfm file and placing the function in this file made it accessible. Marking as sovled!

See my comments at:
Creating Globally Accessible User Defined Functions In ColdFusion (Safer Version)

Here was the final solution:

[Put in application.cfc:]

<cffunction name="onApplicationStart">

. . . snip . . .

<cfscript>
application.globalmethods = structnew();
keys = structkeylist(this);
for (i=1; i LTE listlen(keys); i=i+1) {
key = listgetat(keys,i);
if (iscustomfunction(this[key]) and left(lcase(key),2) NEQ "on")
structinsert(application.globalmethods, key, this[key]);
}
application.registerglobalmethods = this.registerglobalmethods;

</cfscript>

. . . snip . . .

</cffunction>

<cfinclude template="GlobalFunctions.cfm">

<cffunction name="registerglobalmethods" output="no">
<cfset StructAppend(variables, application.globalmethods, true)>
</cffunction>

Finally, in any cfc that uses a global function, call the register function, then you can use any global function (with no scope prefix):

<cfset application.registerglobalmethods();>

Now, you could skip the register function and just use:

<cfset StructAppend(variables, application.globalmethods, true)>

when ever a cfc needed to use global functions. But I think this is more readable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.