Solved

Passing dynamic parameters to a CFC

Posted on 2006-10-30
5
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

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…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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