• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

Passing dynamic parameters to a CFC

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
WebDvlp
Asked:
WebDvlp
  • 2
1 Solution
 
73SpyderCommented:
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
 
trailblazzyr55Commented:
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
 
trailblazzyr55Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now