mia
mia

Reputation: 1

problems with calling CFC

In my CFM, I am calling my CFC (cfc is named Customers and method or function is called ModifyCustomers) like below:

cfform method="post" action="?">
     <input type="hidden" action="ModifyCustomers" > 
...rest of form...

then...

<!--- determine whether form was submitted and what action is --->

cfif isDefined("FORM") and isDefined("Action") and Action eq "ModifyCustomers">

    !--- create object for cfc ---

cfset AbcCFC = createObject("component", "customers") 


--- drop form data into method ---

cfset AbcCFC.ModifyCustomers(FORM)>


!--- the method will do stuff from form data--->


!---  result from the call to the method  ---

cfset wasBigSuccess = abcCFC.ModifyCustomers(FORM)

BUT, looks like my CFC is not being called..... any suggestions?

Update

Yes, my CFC file is in the same directory.

cfform method="post" action="?"

input type="hidden" action="ModifyCustomers"
...rest of form

/cfform (end of form)



!--- determine whether form was submitted and what action is ---

cfif isDefined("FORM") and isDefined("Action") and Action eq "ModifyCustomers"

    !--- create object for cfc ---

cfset AbcCFC = createObject("component", "customers") /


!--- drop form data into method ---

cfset AbcCFC.ModifyCustomers(FORM)

Method will run...

Check result... cfset wasBigSuccess = AbcCFC.ModifyCustomers(FORM)

/cfif

Part of CFC code:

cffunction name="ModifyCustomers" access="remote" returntype="String" output="false" 

        hint="Modify customers in the database"

   cfargument name="firstname" required="yes" type="string"

   cfargument name="lastname"  required="yes" type="string"

   cfargument name="email"     required="yes" type="string"

   cfargument name="manage"    required="yes" type="string"

  cfset var Customers = ""

  cfset var retVal = "0"

  cfset final = "0"

    <!--- If manage = Subscribe, run Addcustomers query. If record count is 0, user is already
        in the database, if record count is 1, query successflly ran and added user. Email is set as Unique
        in the database, so I used an "Ignore" below to bypass the system generated error and will show message
        stating that the user is already in database for newsletter--->

       <cfif Manage eq "Subscribe">
               <cfquery name="Addcustomers" datasource="LizDataSource" result="final">
     INSERT IGNORE INTO users (firstname, lastname, email)
          VALUES(
           <cfqueryparam value="#trim(form.firstname)#" cfsqltype="cf_sql_varchar">,
            <cfqueryparam value="#trim(form.lastname)#"  cfsqltype="cf_sql_varchar">,
            <cfqueryparam value="#trim(form.email)#"     cfsqltype="cf_sql_varchar">
                )       
               </cfquery>

              <cfif final.recordcount is "0">
                 <cfset retVal = "0">

                    <!---<cfoutput> Email #form.email# is already subscribed to the newsletter!
                    </cfoutput> --->

                    <cfreturn retVal>

My form data is not being written to my database. The query was working before I changed how I was calling the CFC.

Upvotes: 0

Views: 443

Answers (2)

Scott Stroz
Scott Stroz

Reputation: 7519

Instead of passing the form scope to your CFC, try doing this:

<cfset AbcCFC.ModifyCustomers(argumentCollection = FORM) />

This will pass the individual items of the form structure as individual arguments instead of simply passing the entire structure that is the form scope.

Also, isDefined("form") will return true on EVERY page. Instead you should do something:

<cfif structKeyExists( form, "action" ) AND form.action EQ "ModifyCustomers" >

Lastly, you have an with an attribute of 'action'. There is no such attribute. I assume you meant:

<input type="hidden" name="action" value="ModifyCustomers" />

Upvotes: 1

Pyae Phyoe Shein
Pyae Phyoe Shein

Reputation: 13787

It's because of you didn't pass "manage" parameter to CFC from your CFM file?

Upvotes: 0

Related Questions