Skip to main content
Participant
May 31, 2007
Answered

Element is undefined in URL

  • May 31, 2007
  • 2 replies
  • 908 views
I can't seem to use a named field in a URL's querystring when it contains a hyphen. Here's my code:

<body>
item1 = <cfoutput>#url.item1#</cfoutput>
orderID = <cfoutput>#url.orderID#</cfoutput>
card_type = <cfoutput>#url.card-type#</cfoutput>
</body>

I have no problem with item1 or orderID but card-type returns the error message:

" Element CARD is undefined in URL."

This URL is coming from a third party so I can't change it.
This topic has been closed for replies.
Correct answer Newsgroup_User
DARAB wrote:
> I can't seem to use a named field in a URL's querystring when it contains a
> hyphen. Here's my code:
>
> <body>
> item1 = <cfoutput>#url.item1#</cfoutput>
> orderID = <cfoutput>#url.orderID#</cfoutput>
> card_type = <cfoutput>#url.card-type#</cfoutput>
> </body>
>
> I have no problem with item1 or orderID but card-type returns the error
> message:
>
> " Element CARD is undefined in URL."
>
> This URL is coming from a third party so I can't change it.
>

This seems to be the week of the "array notation".

You can not use an invalid variable name string in a dot notation
expression. What ColdFusion is trying to do is evaluate 'url.card'
minus 'type' and can not find an 'url.card'.

To use invalid variable string names one need to use array notation.
url["card-type"] should get you what you want.

2 replies

May 31, 2007
Have you tried dumping the URL scope to see if it's in there any other way?

You could also use the cgi.query_string variable to parse it out if for some reason ColdFusion doesn't like it.

Koen
Newsgroup_UserCorrect answer
Inspiring
May 31, 2007
DARAB wrote:
> I can't seem to use a named field in a URL's querystring when it contains a
> hyphen. Here's my code:
>
> <body>
> item1 = <cfoutput>#url.item1#</cfoutput>
> orderID = <cfoutput>#url.orderID#</cfoutput>
> card_type = <cfoutput>#url.card-type#</cfoutput>
> </body>
>
> I have no problem with item1 or orderID but card-type returns the error
> message:
>
> " Element CARD is undefined in URL."
>
> This URL is coming from a third party so I can't change it.
>

This seems to be the week of the "array notation".

You can not use an invalid variable name string in a dot notation
expression. What ColdFusion is trying to do is evaluate 'url.card'
minus 'type' and can not find an 'url.card'.

To use invalid variable string names one need to use array notation.
url["card-type"] should get you what you want.