Solved

Passing dynamic parameters to a CFC

Posted on 2006-10-30
5
317 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

18 Experts available now in Live!

Get 1:1 Help Now