Variables Naming Conflict

27 June 2007 01:28 (EST)
Recently I had a chance to play a bit with Facebook API, which uses REST-based interface. There is ColdFusion client library developed by Andrew Duckett and called Facebook REST Client CFC and CFMX Facebook Application Starter example written by Cory Johnson.

While developing application with use of FBML instead of IFRAME (which works just fine) Facebook server has started throwing "http error 500" upon calls to Callback URL of my application. Source code of error page had details of the error commented out — "Form entries incomplete or invalid".

Digging deeper into the problem I have discovered that CFMX server has following rule for variables naming:
Programming ColdFusion by Rob Brooks-Bilson, Chapter 2, Variables:
Avoid choosing variable names that end in _date, _eurodate, _float, _integer, _range, _required, or _time, as these are reserved suffixes for server-side form validation variables and can cause naming conflicts.

One of the POST request variable from Facebook server is named FB_SIG_TIME and causing an error.

Fortunately you can use Application.cfm to solve the problem, like this:
<cfif StructKeyExists(form, "FB_SIG_TIME")>
   <cfset form.FB_TIME_SIG = form.FB_SIG_TIME />
   <cfset StructDelete(form, "FB_SIG_TIME", true) />
</cfif>

Good luck!
Tags coldfusion cfc cfmx facebook api rest client server

AddThis Social Bookmark Button

Melbourne CFUG (June) CFEclipse

Comments

Raymond Camden: 27 June 2007 01:56 (EST)

You should file a bug to allow folks to disable this behavior by CF. Perhaps as a setting in the This scope in Application.cfc. You can do this at www.adobe.com/go/wish

Dmitry Yakhnov: 27 June 2007 13:10 (EST)

This is a documented rule of CFML, so guys just need to be aware of, as I personally never heard of this :) I don't think that Facebook nor Adobe are going to change their behavior just because of this small trouble.

OpenIDopenid.mrbuzzy.biz: 16 July 2007 21:33 (EST)

Thanks I'm glad I found this.
Note: If you want to use Application.cfc the fix need to go in the contructor area(?) of Application.cfc. It won't work in OnRequestStart or OnRequest, it's too late by then :)

Dominic Watson: 23 July 2007 18:44 (EST)

Brilliant, thanks for sharing that :)

Anthony: 20 September 20:27 (EST)

You said using FBML works fine? I can use my app fine via the direct URL but when I try to get at it from facebook I get a 500 error and in the page source I see this error:
The system has attempted to use an undefined value, which usually indicates
a programming error, either in your code or some system code. <p>

Null Pointers are another name for undefined values.

Any ideas of what I might be able to do to build an FBML app?

Dmitry Yakhnov: 24 September 00:52 (EST)

Hi Anthony,

Yes, I have CF-FBML application at Facebook which is working just fine:
The Friend of a Friend (FOAF)

Your error has nothing to do with trouble I have described in this post. See details on your error here.

Harel Malka: 16 November 03:30 (EST)

This sucks for many reasons and should be either dropped from CF or be allowed to be turned off.
Bebo exhibits the same problem as it uses the facebook standard. (I ran into this previously with an ORM system and a legacy database that used exactly that naming convention...)
I've tried your solution and it doesn't seem to work for me on CF8... :o(
Harel

Harel Malka: 16 November 03:32 (EST)

Dmitry, this might not be an official 'bug' but it is definitely a cancer in CF.

will: 27 November 18:28 (EST)

how do i see who is writing in my facebook honesty box?

Dominic Watson: 17 December 19:39 (EST)

This code does not work in CF8! Instead, you should do the following in Application.cfm/cfc:

<cfset form.FBSIG = form.FB_SIG><!--- or whatever you wish to rename it --->
<cfset form.FB_SIG = "">

Check out http://www.coldfusionjedi.com/index.cfm/2007/9/21/Fixing-the-Facebook-Problem-and-why-one-ColdFusion-feature-needs-to-die#cE723F776-19B9-E658-9D30FB05D6A0873E for discussion.

Huge: 21 January 22:00 (EST)

I solved the problem with:
<!--- 1. cf6+ tries server-side form validation on various form field names, fix: --->
<cfset s_trouble = "integer,float,range,date,time,eurodate,key,expires,added,friends,canvas,user,method,fieldnames,fix">
<cfloop list="#StructKeyList(form)#" index="formField">
<cfif ListFindNoCase(s_trouble, ListLast(formField,'_'))>
<cfset StructInsert(form, formField & '_CFFIX', form[formField])>
<cfset StructDelete(form, formField)>
</cfif>
</cfloop>

Huge: 21 January 22:14 (EST)

it was an error, i had a cfabort.

Sorry, i continue with it.

Huge: 22 January 01:04 (EST)

Now I found a solution:

Maybe some of ours have in Application.cfm(cfc) this code:

<cfif StructKeyExists(form, "fb_sig")>
<cfinclude template="fb_post.cfm">
<cfelse>
<cfinclude template="fb_get.cfm">
</cfif>

And when CF procces de page, load de index.cfm page.

It will be the normal processing, but I dont know why, but if you write this:

<cfif StructKeyExists(form, "fb_sig")>
<cfinclude template="fb_post.cfm">
<cfelse>
<cfinclude template="fb_get.cfm">
</cfif>

<cfinclude template="index.cfm">
<cfabort>

The page loads correctly... and why?? I dont know, but it loads....

Urgggg!!!

Drop a comment... don't be shy