Calling a CFC directly from a form

Posted on 2008-10-30
Last Modified: 2012-05-05
Is it possible to call a CFC directly from the action tag in <cfform>?

if not what is the best way to invoke the cfc from a form?

Question by:Hulfy
  • 2
LVL 36

Accepted Solution

SidFishes earned 500 total points
ID: 22844471
yes you can

<form method="post" action="com/myCFC.cfc?method=yourFunction">

however best practice says when designing cfc's, all input should be agnostic (to allow for other potential inputs like web services) and should use arguments

to do this create a form handler

<form method="post" action="actFormHandler.cfm">

<input type=="hidden" name="formid" value="f1">
<input type="submit">

in actFormHandler.cfm

<cfswitch expression="form.formid">

<cfcase value="f1">
<cfinvoke component="com.myCfc"
                  ReturnVariable = "results">
      <cfinvokeargument name="ID" value="#form.ID#">            
      <cfinvokeargument name="value2" value="#form.value2#">            


note in either case you need to add access="remote" to your cfc function

LVL 36

Expert Comment

ID: 22844490
oh and if you're not already use arguments in the cffunction

<cffunction name="doFormPost1" hint="I process a form"
      <cfargument name="ID" required="true">
      <cfargument name="value2" required="true">

<!--- do stuff --->


Author Comment

ID: 22848151
Thanks Sid

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now