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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem in SELECT Statement 5 85
coldfusion create csv file dymanic pass heading and columns 31 140
<cffile cannot delete a file 4 53
Update cached table in H2 database 6 58
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

825 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