Calling a CFC directly from a form

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,
HulfyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
SidFishesConnect With a Mentor Commented:
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
 
SidFishesCommented:
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
 
HulfyAuthor Commented:
Thanks Sid
0
All Courses

From novice to tech pro — start learning today.