Solved

Passing dynamic parameters to a CFC

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WSUS Client Issues 52 1,671
Reverse Proxy Server 6 82
Change local server setting in php 6 87
listing all functions in JavaScript 19 202
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

777 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