Solved

Passing dynamic parameters to a CFC

Posted on 2006-10-30
5
324 Views
Last Modified: 2013-12-24
Hi,
I have a form which has dynamic input fields.
...
<cfform action="IconController.cfc?method=updateIcon" method="post">
...
<cfloop query="languages">
<tr>
      <td class="shadow" valign="top">#languages.name#<td>
      <td>
      <cftextarea name="name_#languages.name#">#evaluate('iconData.name_#languages.name#[iconData.currentRow]')#</cftextarea>                  
      </td>            
</tr>
</cfloop>
...
</cfform>
When I want to submit those From values to my CFC "IconController.cfc? method...
How can I get those Form fields values in my CFC ?
I have tried on the following way but it does not works to construct cfarguments with a loop?
In the IconController I would like to update the current Icon information stored in a database.

<cfcomponent name="IconController">
<cffunction name="updateIcon" access="remote" output="false">
    <cfargument name="icon_id" type="string" required="Yes">
    <cfargument name="icon_name" type="string" required="Yes">
     <cfargument name="icon_order" type="string" required="Yes">
     
     <cfloop query="languages">
      <cfargument name="#evaluate('name_#languages.name#')#" type="string" required="Yes">      
     </cfloop>
            
</cffunction>
</cfcomponent>

Is it possible to explain me a better way or give me a hint to solve this problem.
Thanks in advance.
0
Comment
Question by:WebDvlp
  • 2
5 Comments
 
LVL 9

Expert Comment

by:73Spyder
ID: 17834540
Is there a max # of the languages?

If so you could do list each one and change the required to false.

<cfargument name="lang_1" type="string" required="false" default="">    
<cfargument name="lang_2" type="string" required="false" default="">  

and so on.

Then in the query you check to see if the arguments.lang_1 NEQ "" 

Does this make sense?


0
 
LVL 20

Accepted Solution

by:
trailblazzyr55 earned 125 total points
ID: 17834558
when you don't know exactly what's going to be passed to your CFC/Method then you can do something like this....
basically you grab the whole form scope and then setup conditions in your function/method...

submit to your CFC

<cfcomponent name="IconController">
<cffunction name="updateIcon" access="remote" output="false">
    <cfargument name="frm" type="struct" required="Yes" default="#form#"> <!--- pass in the entire form scope --->
   <!--- now check for existing form variables in your form scope --->
    <cfif structkeyexists(arguments.frm,"formFieldName")>
       <!--- do something --->
    </cfif>

    <!--- this also allows you to get rid of the loop --->
         
</cffunction>
</cfcomponent>
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17834635
by passing in the entire form scope as well you can just access those field values like so...

<cfcomponent name="IconController">
<cffunction name="updateIcon" access="remote" output="false">
    <cfargument name="frm" type="struct" required="Yes" default="#form#"> <!--- pass in the entire form scope --->

    <!---- with any variables you use in your method, you also want to scope them --->  
    <cfset var myFormFieldOne = "">
    <cfset var icon_id= "">

    <!--- now give them values --->

    <!--- now check for existing form variables in your form scope --->
    <cfif structkeyexists(arguments.frm,"formFieldOne")>
       <cfset myFormFieldOne = arguments.frm['formFieldOne'] />
    </cfif>

    <!--- with one of your examples --->
    <cfif structkeyexists(arguments.frm,"icon_id")>
       <cfset icon_id = arguments.frm['icon_id'] />
    </cfif>  
     
</cffunction>
</cfcomponent>
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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