Skip to main content
Participating Frequently
August 26, 2009
Question

Where to put custom function at?

  • August 26, 2009
  • 1 reply
  • 893 views

Let's say I make a custom function, do I make it a CFC or a tag?


Here is some sample code (I put in bold my function call)

<cfif IsDefined("form.submit")>

    <cfset data.comment = Trim(HTMLEditFormat(form.comment))>
    <cfset data.name = Trim(REReplace(form.name, "[^A-Za-z0-9 ]", "", "all"))>
    <cfset data.location = Trim(CustomFunction(form.location))><!--- where to put it? as cfc or as a tag? --->
    <cfif data.comment NEQ "">       
        <cfif data.name EQ "">
            <cfset data.name = "Anonymous">
        </cfif>
        <cfinvoke
        component="guestbook.cfc.db"
        method="insert_comment">
        <cfinvokeargument name="form_data" value="#data#"/>
        </cfinvoke>
    <cfelse>
        <cfset message="Comment is required!">
    </cfif>
</cfif>

This topic has been closed for replies.

1 reply

uzeruzerAuthor
Participating Frequently
August 26, 2009

nevermind i think I found the info

cfdocs/htmldocs/help.html?content=reuseIntro_1.html

I believe I need to put it as a TAG in a CFM file since its a simple UDF

Inspiring
August 26, 2009

Custom tags are different than udfs.  Let's stick with udfs.  Your location choices are:

1.  If only one template is going to use it, you can put it in that template.  Otherwise,

2. You can put it in a .cfm file and cfinclude that file whenever you want to call the function, or

3. You can put it into a .cfc.

A little while back, someone ran some tests and posted the results on one of these forums.  The gist of it was that Option 2 would run faster than Option 3.