Solved

Calling a CFC directly from a form

Posted on 2008-10-30
3
352 Views
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?


Thanks,
0
Comment
Question by:Hulfy
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
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">
</form>
then

in actFormHandler.cfm

<cfswitch expression="form.formid">

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

etc

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







0
 
LVL 36

Expert Comment

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


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

<!--- do stuff --->
</cffunction>

0
 

Author Comment

by:Hulfy
ID: 22848151
Thanks Sid
0

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 http://bit.ly/XDcourse.

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