Nice work Peter. We have an application where certain site specific 
information is contained within the application scope on the frontend 
(self contained applications per site) but within the session scope on 
the backend (an admin application for updating the info of multiple 
sites), and created an object that would take the scope name to know 
which scope to apply the structure to. Great solution you worked here.

Steve "Cutter" Blades
Adobe Certified Professional
Advanced Macromedia ColdFusion MX 7 Developer
_____________________________
http://blog.cutterscrossing.com

Peter Boughton wrote:
> You're mixing up the global Form scope, with your Arguments.Form struct, and 
> the idea of var scoping function-local variables.
> 
> You're also missing half the point of creating functions: abstracting and 
> modularising common functionality - what happens if you want to trim another 
> scope or structure?
> 
> Here's a function that does what you want, but can also be used against Url 
> scope, Session scope, or any structure you like.
> 
> <cffunction name="trimStruct" returntype="Struct" output="false" 
> access="public">
>       <cfargument name="aStruct" type="Struct"/>
>       <cfset var Item = ""/>
>       <cfloop item="Item" collection="#Arguments.aStruct#">
>               <cfset Arguments.aStruct[Item] = Trim(Arguments.aStruct[Item])/>
>       </cfloop>
>       <cfreturn Arguments.aStruct/>
> </cffunction>
> 
> <cfset Form = trimStruct(Form)/>
> <cfset Url = trimStruct(Url)/>
> <cfset A_Random_Structure = trimStruct(A_Random_Structure)/>
> 
> 
> Hope that helps?
> 
> 
> 
>>I haven't built a simple udf in forever, but decided to do one for my 
>>trimming of formfields. I tried sticking a <cfset var form = ""> right 
>>above the loop, but I get an error:
>>
>>Cannot declare local variable FORM twice.
>>
>><cfcomponent>
>>      <cffunction name="cleanFormfields" access="public" 
>>returntype="struct">
>>              <cfargument name="form">
>>                  <cfloop list="#ARGUMENTS.FORM.fieldnames#" 
>> index="thisfield">
> 
>                
> 
>><cfset FORM[thisfield] = Trim(ARGUMENTS.FORM[thisfield])>
> 
>            
> 
>></cfloop>
>>              <cfreturn form>
>>      </cffunction>
>></cfcomponent>
>>
>>Am I not supposed to var this one?
>>
>>Thanks,
> 
> Will
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion MX7 by AdobeĀ®
Dyncamically transform webcontent into Adobe PDF with new ColdFusion MX7. 
Free Trial. http://www.adobe.com/products/coldfusion

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:271859
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
  • Re: udf var Cutter (CFRelated)

Reply via email to