the keys in the struct that comprises the argumentCollection are received by
the method as individual cfarguments.
so if your form struct has keys 'firstName' and 'lastName', and the form was
passed in as an argumentCollection, you'd have arguments.firstName and
arguments.lastName.
also you need to var that <cfset form_errors = structNew()>
it also -might- not be a bad idea, if only for documentation purposes, to
specify your cfarguments inside of the cffunction.
so you'd have:
<cffunction name="validate_comment_data" output="false" returntype="struct"
hint="i validate comment form data">
<cfargument name="firstName" type="string" required="true" />
<cfargument name="lastName" type="string" required="true" />
<cfset var errorStruct = structNew() />
<cfif not len(trim(arguments.firstName)) gt 0>
<cfset errorStruct.firstName = "first name is required" />
</cfif>
<cfif not len(trim(arguments.lastName)) gt 0>
<cfset errorStruct.lastName = "last name is required" />
</cfif>
<cfreturn errorStruct />
</cffunction>
On Wed, Oct 22, 2008 at 7:20 PM, Rick Faircloth <[EMAIL PROTECTED]>wrote:
> I've been trying to figure out how to use a CFC for validating form
> data, but I can't find any info on how the code should be constructed.
>
> I've been using the CFC and the form variables in the code, but I'm
> trying to get away from accessing data directly in the CFC.
>
> The invocation I'm using:
>
> <cfinvoke component = "components.comments"
> method =
> "validate_comment_data"
> argumentCollection = "form"
> output = "false"
> access = "public"
> returnVariable = "form_errors">
>
> Then I just use the CFC like this:
>
> <cffunction name = "validate_comment_data"
> displayname = "validate_comment_data"
> hint = "Validate comment form data
> before inserting or updating"
> output = "false"
> access = "public">
>
> <cfset form_errors = structNew()>
>
> <cfif not len(trim(form.first_name))>
> <cfset form_errors.first_name = "Please enter your first name.">
> </cfif>
>
> <cfif not len(trim(form.last_name))>
> <cfset form_errors.last_name = "Please enter your last name.">
> </cfif>
>
> etc....
>
> <cfreturn form_errors />
>
> </cffunction>
>
> But how would I change the cffunction code to make use of the
> argumentCollection = "form"
> variables?
>
> <cfif not len(trim(arguments.first_name))> ???
>
> Some clues for the clueless, anyone?
>
> Thanks,
>
> Rick
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314283
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4