Quick Tip: Dealing with Freaky Facebook Form Fields

A user working on a Facebook application ran into an interesting problem this morning. Form data was being sent to his server with field names that included a bracket. So instead of a simple form.foo variable, he was sent form.foo[]. When he attempted to make use of the field…

<cfoutput> #form.foo[]# </cfoutput>

ColdFusion threw an error. No big surprise there. The solution though is to simply treat the form as a structure:

<cfoutput> #form["foo[]"]# </cfoutput>

If you wanted to copy the values you can use:

<cfset saneList = form["foo[]"]>

You get the idea.

By the way, I will use this opportunity to remind people of another Facebook issue, and that’s with the use of form fields that turn on ColdFusion’s ancient automatic form handling. I discuss a workaround here, but you should remember that ColdFusion 9 now includes a fix for this behavior. Simply include this.serversideformvalidation=false in your Application.cfc. To be clear, it doesn’t turn off any server side validation you write. It simply disables the old automatic validation that no one uses (except when they accidentally run into it).

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments