Hi, all...

Still figuring out the best way to employ CFC's into my workflow.

Now I'm working on incorporating CF validation  into my code using CFC's.
I've got a working solution, but would like some suggestions on how to
improve it.

Thanks for any suggestions!

Rick

Here's a slimmed-down version with the highlights (or lowlights :o) :

products.cfm:
-----------------

    <cfif isdefined('form.fieldnames')>
   
        <cfinvoke    component                 =    
"imprint-warehouse-sm.components.products"
                           method                       =    
"validate_product_insert_data"
                           returnVariable            =    "form_errors"
                           argumentCollection    =    "#form#" />
                   
    </cfif>

    <form action="products.cfm" method="post">

        Product Name <cfif isdefined('form_errors.name')> &nbsp;&nbsp; 
Please enter a name for this product.</cfif><br>
        <input    name    =    "name"            type="text"        
value=""     size="50"    >    <br>

        Description <cfif isdefined('form_errors.name')> &nbsp;&nbsp; 
Please enter a description for this product.</cfif><br>
        <input    name    =    "description"        type="text"        
value=""    size="50"    >

        <input    name    =    "submit"               type="submit"    
value="Submit">

    </form>


products.cfc
----------------

<cffunction    name                   =    "validate_product_insert_data"
                     displayname        =    "validate_product_insert_data"
                     hint                      =    "Validates form data 
before product insert"
                     output                  =    "false"
                     access                 =    "remote">
                   
            <cfset form_errors = structNew()>
            <cfset temp = structClear(form_errors)>

             <cfif Not Len(Trim(form.name))>
                  <cfset form_errors.name = "Please enter a name for 
this product.">
             </cfif>
   
             <cfif Not Len(Trim(form.description))>
                  <cfset form_errors.description = "Please enter a 
description of this product.">
             </cfif>
   
            <cfreturn #form_errors# />
                   
    </cffunction>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:314153
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to