Structures from URL and FORM scope

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Structures from URL and FORM scope

    I've recently discovered an abborant behavior of CF MX. I vaguely remember
    that this did not work this way in CF 5, but I could be mistaken. But check
    this example.

    I pass a URL variable called "RFA.click" with a value of "IOB.editDataForm".

    This creates a variable in the URL scope called "RFA.click" with that value.

    Now, if I param that like:
    cfparam name="url.RFA.click" default="IOB.editForm"

    The value of url.RFA.click will end up being IOB.editForm when it should have
    been IOB.editDataForm

    This is because using cfparam or cfset to create a variable name like
    RFA.click will automatically create a structure called "RFA" with an key called
    "click".

    But, passing on the URL will create an element in the url struct called
    "RFA.click".

    This variable is not created as a structure as it SHOULD be.

    Furthermore, if you do check for the existance of the struct "RFA", and then
    create it in the same scope, you loose the origional URL scoped variable.

    Clearly this is either a bug, or unexpected behavior. All variables in passed
    scopes should be put to the same scrutiny that a set variable is.

    What I am trying to accomplish is something like this.

    I always copy all URL and FORM scoped variables to the request scope, and then
    refer to them form there. I use 2 StructAppend statements to append the entire
    URL and FORM scope to REQUEST in 2 lines of code.

    I then put all my flow control variables into a structure nested in the
    REQUEST structure called "RFA". The plan was to be able to overide these flow
    control variables with ones passed in forms, or on URLs. It's seems to me that
    this always worked back in CF 5 (maybe not)?

    Some debugging samples:

    CFDUMP of REQUEST:
    action : iobUpdate.budgetSearch
    cfdumpinited : TRUE
    rfa : struct [empty]
    rfa.click : iobUpdate.budgetDataEditForm

    Request dump from debugging:
    Request Parameters:
    action=iobUpdate.budgetSearch
    cfdumpinited=TRUE
    date=02/28/2005
    file_requested=index.cfm
    rfa=Struct (45)
    rfa.click=iobUpdate.budgetDataEditForm
    sort_field=bud_no

    See here how the rfa struct exists with 45 keys, but yet a variable called
    rfa.click exists as well? The kicker is there is no way to refer to this
    variable, any reference to RFA.anything looks in the structure.

    Any ideas on a work around?

    Lupus 23 Guest

  2. Similar Questions and Discussions

    1. Sporadic loss of FORM scope data
      Up to 10% of my users get errors when submitting forms. FORM scope is totally gone (no FIELDNAMES, no hidden fields, zip, nada) I have done the...
    2. FORM scope and CFCs?
      I have a application where users take a 90 question multiple choice test, after each of the 6 pages I want to save their answers to an array for...
    3. faking a form scope
      I'm setting up dynamic variables that need to mimic a form scope. currently, I'm setting them like: <cfset FORM = #trim(RowArray)#> This was...
    4. Array scope and a form
      I'm having trouble with the scope of an array. I define it then try to populate it within a form, but once out of the form, the original values are...
    5. Problem with sessions (in global scope vs class scope)
      Hello, i'me having a wierd problems with sessions. PHP 4.3.3, Register globals is on, and the sessions module is installed. if i have a page like...
  3. #2

    Default Re: Structures from URL and FORM scope

    I did some tests and was able to reproduce simular behavior on a CF 5 server.
    Lupus 23 Guest

  4. #3

    Default Re: Structures from URL and FORM scope

    Passing on the URL is doing the equivalent of this:

    URL["dotted.variable.name"]

    Dot notation assumes each element is substructure.

    I can see how this might be confusing, but it doesn't seem anomolous to me.

    --

    Adam
    Adam Cameron Guest

  5. #4

    Default Re: Structures from URL and FORM scope

    It doesn't seem anomolous to you that CFPARAM will set a value to an existing
    variable?

    Clearly request.RFA.click is defined, as shown by the request scope variable
    dump. Or even in CFDUMP. But yet when a CFPARAM is performed against the same
    name it sets the value assuming the variable is undefined.

    I'm sorry but I'm having trouble following your logic.

    Let's look at this one more time. Here is a CFDUMP of the REQUEST structure.
    <cfdump var="#request#">
    OUTPUT:
    REQUEST:
    rfa struct (45)
    rfa.click iobUpdate.budgetDataEditForm

    <cfif IsDefined("request.RFA.click")>
    HERE IT IS<br>
    <cfelse>
    NOPE
    </cfif>
    OUTPUT:
    NOPE

    I would think that any time that IsDefined() returns false on a variable that
    exists should be considered anomolous.

    Lupus 23 Guest

  6. #5

    Default Re: Structures from URL and FORM scope

    > It doesn't seem anomolous to you that CFPARAM will set a value to an existing
    > variable?
    Well, there's two things at work here:
    1) you don't seem to understand that url["one.two"] is a different variable
    from URL.one.two. They are.
    2) What you're actually suggesting doesn't happen anyhow! (which surprised
    me, to be honest)

    Try this:

    <!--- dsp.cfm --->
    <a href="./act.cfm?dot.in.name=true">click</a>

    <!--- act.cfm --->
    <cfparam name="url.dot.in.name" default="false">
    <cfdump var="#url#">

    When I click on the link, I get told that URL["dot.in.name"] is TRUE. Not
    FALSE.

    If I ask whether isDefined("URL.dot.in.name"), I get yes.

    If I extend this, as below, I still get predictable answers:

    <!--- act.cfm --->
    <cfparam name="url.dot.in.name" default="false">
    <cfif not structKeyExists(URL, "dot")>
    <cfset url.dot = structNew()>
    </cfif>
    <cfdump var="#url#">


    My dump now lists both DOT and DOT.IN.NAME as different variables.

    Here's a couple of quotes from your original post:

    >> This variable is not created as a structure as it SHOULD be.
    This is incorrect. The variable created is URL["RFA.click"] not,
    URL.RFA.click. These are two DIFFERENT variables.
    > Furthermore, if you do check for the existance of the struct "RFA", and then create it in the same scope, you loose the origional URL scoped variable.
    Well... err.. *no*, you don't.

    > Clearly this is either a bug, or unexpected behavior. All variables in passed scopes should be put to the same scrutiny that a set variable is.
    Yes. But you have to understand that CF will aloow variables names to have
    dots in them, but if so, one has to refer to them in struct["key.name"]
    notation, not struct.key.name notation, as a dot in CF natively suggests a
    substructure.

    URL variables are handled by the webserver, not the CF server, so they
    cannot know that ?foo.bar=true ought to be created as URL.foo.bar = true;
    it just creates a variable called "foo.bar" in the URL scope, and gives it
    value "true".

    Same as if you say URL["key##name"]. This refers to a variable called
    key#name in the URL struct. It does not refer to the "special meaning" of
    a pound-sign in CF, which would just result in your code breaking ;-)

    Make sense?



    --

    Adam
    Adam Cameron Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139