ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old November 19th, 2004, 04:09 PM
CF_Bob CF_Bob is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 CF_Bob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Pound signs in variable names

Hi folks,

This is a kinda wierd one. I've got some software here running on my CFMX server to handle e-commerce. I'm trying to create a custom front-end for some of the product categories but I'm running into a bit of trouble with how this software tracks users. Apparently the software sets a cookie when the user first visits and this cookie contains an ID that I need to use. Now it should be a simple matter to retrieve this information from the cookie except there is a catch... the variable in the cookie that CF uses to access this informaton is named:

store1#CustomerID

Yes, that's right. The variable name ITSELF contains a pound sign. This is causing a huge headache as the CF engine think's I'm calling a variable in this variables name when I try to do anything with it.

For Example, I can try to access the data in the cookie var by using something like this:

<cfset CookieData = cookie.store1#CustomerID>
OR
<cfset CookieData = cookie.store1##CustomerID>

Both of these methods result in an "Invalid CFML Construct" error. Anyone have a suggestion?

Reply With Quote
  #2  
Old November 19th, 2004, 04:36 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,626 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 6 m 34 sec
Reputation Power: 53
You cannot have a pound sign in a variable name:

- A variable name must begin with a letter, underscore, or Unicode currency symbol.
- The initial character can by followed by any number of letters, numbers, underscore characters, and Unicode currency symbols.
- A variable name cannot contain spaces.

I would try stripping the pound sign out of the cookie name before doing anything with it in CF. Try replace() or replaceNoCase(). It might be tricky.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Last edited by kiteless : November 19th, 2004 at 04:39 PM.

Reply With Quote
  #3  
Old November 22nd, 2004, 09:10 AM
CF_Bob CF_Bob is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 CF_Bob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That may be the case but that doesn't mean it's not possible to have a var name with a "#" character. I don't have control of how the var is set in the cookie, the code that does this is setup in a java class that I don't have source to.

I noticed that if I enable debugging I can see that the var is listed under "Cookie Variables" with the "#" character in the var name. Somehow CFMX can access it, how the heck can I?

Reply With Quote
  #4  
Old November 22nd, 2004, 09:58 AM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 5 sec
Reputation Power: 22
Send a message via AIM to bocmaxima
It knows its there, of course, because it's in the Cookies collection. The problem is that a hash mark is a reserved character in CFML, and if it appears anywhere in the document then CF interprets that as the start of an insert.
One possible workaround is to use StructKeyArray. This will turn your cookies collection into an array and then you can try to figure out, through loops and such, where and what the value of these cookies are.
You can also try to use Eval in CFScript for something like:
Eval("newvar = Cookies.#cookiename")

Really though, I'd suggest changing languages. Just do it in PHP or something else that doesn't have # as a reserved character since these cookies are so integral to your application.

Hope that helps.

Reply With Quote
  #5  
Old November 22nd, 2004, 10:30 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,626 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 6 m 34 sec
Reputation Power: 53
Like I said, replace the pound sign with somethine else. It can be done it just takes some fiddling. This replaces the pound sign with a tilde as an example.

<cfset theCookieName = "store1##customerID" />
<cfset cookieStruct = structNew() />
<cfset structInsert( cookieStruct, theCookieName, 'The Cookie Value' ) />
<cfloop collection="#cookieStruct#" item="thisKey">
<cfif findNoCase( '##', thisKey )>
<cfset tempStruct = structNew() />
<cfset newKeyName = replaceNoCase( thisKey, '##', '~', 'All' ) />
<cfset structInsert( tempStruct, newKeyName, cookieStruct[thisKey] ) />
</cfif>
</cfloop>
<cfset cookieStruct = duplicate( tempStruct ) />
<cfdump var="#cookieStruct#">

Since pound signs are reserved characters in CF it won't let you directly use the variable if it has a pound sign in the name. Your only two choices are to replace the pound sign or not use ColdFusion.

Reply With Quote
  #6  
Old January 2nd, 2005, 10:31 PM
lakota_stars lakota_stars is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 lakota_stars User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Using a "#' sign

you can use
ampersand poundsign 35 semicolon
no spaces between the characters
this is the 'number sign' in html markup language

go here to see it:
http://www.w3.org/MarkUp/html-spec/html-spec_13.html#SEC13

Reply With Quote
  #7  
Old January 3rd, 2005, 09:46 AM
VelvettFogg VelvettFogg is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 34 VelvettFogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 13 m 46 sec
Reputation Power: 4
Read the cookie with Javascript, and then re-save it without the # sign?

Reply With Quote
  #8  
Old March 4th, 2005, 03:35 AM
JeffHowden JeffHowden is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 1 JeffHowden User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 19 sec
Reputation Power: 0
Thumbs up Better Idea

Just double up the hashes. That's the standard method for escaping them in ColdFusion. Be forwarned that you'll have to treet this variable name differently though. You'll never be able to use it in regular dot notation. You're stuck to using square brackets. So, instead of "cookie.store1#CustomerID", try "cookie['store1##CustomerID']". It's just that easy.

Jeff Howden

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Pound signs in variable names


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway