#1
  1. Put a potato on it!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Location
    Maryland
    Posts
    304
    Rep Power
    971

    Syntax problem with a struct's keys


    Recently we changed the way our application was making ajax calls so I've been rewriting it and noticed right away that when the ajax gets fired and posts it has parameters called "c0-param1", "c0-param2" etc. I plan on asking the javascript board why drwengine does that, but right now I'd like to know if there's a way to change the name of an existing struct key.

    The page posts to itself through ajax. All the parameters come through in the form scope with the information I am then passing to a function that will update a customer's information.

    This is what the parameters look like when I cfdump the form variable:

    c0-param0 string:contact_id,newEmail
    c0-param1 string:6iZcEJ3-xkhO-BsZT-9h2qbrycQg6U
    c0-param2 string:test@sample.com

    If I tried to pass form.c0-param0 to my function it says it can't find the key called "c0". What I've done to get around this is:

    Code:
    <cfset params=structNew()>
    <cfset params.allparams = "">
    <cfset params.contact_id = "">
    <cfset params.password = "">
    
    <cfif isDefined("form.ajax")> <!--- when the ajax posts, the form struct gets the "ajax" key which is set to true --->
    	<cfset params.allparams = replace(structFind(form, "c0-param0"), "string:", "")>
    	<cfset params.contact_id = replace(structFind(form, "c0-param1"), "string:", "")>
    	<cfset params.password = replace(structFind(form, "c0-param2"), "string:", "")>
    </cfif>
    Assigning the values to a new struct and pass that along. Is there any way for me to set the keys of "form" to something without a hyphen? I looked through the docs and Googled but I haven't seen anything that would allow me to do that so I figured I'd just try once more here and be sure. This was the best way I could think to do it, but I'm really new to ColdFusion so if anyone has a better way to do it, please tell me, I'd appreciate it.
    "Those who can make you believe absurdities can make you commit atrocities."
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    Just in case, did you try using the bracket syntax:

    form['c0-param0']

    ?
  4. #3
  5. Put a potato on it!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Location
    Maryland
    Posts
    304
    Rep Power
    971
    That was it. Thanks so much, Kiteless!
    "Those who can make you believe absurdities can make you commit atrocities."

IMN logo majestic logo threadwatch logo seochat tools logo