views:

83

answers:

2

What is the syntax for passing the form scope into a cfc with access="remote"? I have:

<cfcomponent>
<cfset Variables.Datasource = "xxx">

<cffunction name="Save" access="remote">
    <cfset var local = {}>

    <!--- todo: try/catch --->  
    <cfif arguments.PersonID>
        <cfquery datasource="#Variables.Datasource#">
        UPDATE Person
        SET FirstName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.FirstName#">
        ,LastName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.LastName#">
        WHERE PersonID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.PersonID#">
        </cfquery>
        <cfset local.result = arguments.PersonID>
    <cfelse>
        <cfquery name="local.qry" datasource="#Variables.Datasource#">
        INSERT INTO Person(FirstName,LastName) VALUES(
        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.FirstName#">
        ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.LastName#">
        );
        SELECT PersonID FROM Person 
        WHERE PersonID=Scope_Identity()
        </cfquery>
        <cfset local.result = local.qry.PersonID>
    </cfif>
    <cfreturn local.result>
</cffunction>
</cfcomponent>

I need to pass in form.PersonID, form.firstname, form.lastname.

+1  A: 

Your remote function can accept either a struct argument, or 3 string arguments (PersonID, firstname and lastname).

See <CFARGUMENT> in documentation

Henry
Henry, thanks for the response. I wasn't clear enough. I'm learning jQuery, so the answer had to do with the .serialize() function in jQuery.
cf_PhillipSenn
Phillip - if your question is about jQuery, please edit your question to explicitly ask about that. Also, you can add the jQuery tag to help people who have an interest in that find it. I would have answered the question as stated exactly like @Henry.
Ben Doom
Ouch. OK, I'll rethink and reword this question in a little while.
cf_PhillipSenn
btw, you don't need to use jQuery if you don't wanna. cfajaxproxy can serialize form for you too. :)
Henry
+1  A: 

One unrelated thing. In cf9 you already have the local struct waiting. More on this here http://forta.com/blog/index.cfm/2009/6/21/The-New-ColdFusion-LOCAL-Scope

intnick
Good note intnick. I looked at http://www.byteout.com/ and am impressed with your work. Right now my shared server is on 8, so I am still coding in 8 syntax even though I have 9 on my localhost.It's going to be huge change when I start coding 9 because of the script syntax!
cf_PhillipSenn