Quick Tip: Dealing with Freaky Facebook Form Fields

This post is more than 2 years old.

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 senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

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

Archived Comments

Comment 1 by David C-L posted on 12/15/2009 at 9:45 PM

That issue isn't unique to Facebook-- it's a PHP thing. In PHP, fieldname[] is a convention used for groups of fields (usually, but not always, groups of checkboxes); PHP automatically converts these form fields to arrays if they are named using this convention.

Comment 2 by Raymond Camden posted on 12/15/2009 at 11:45 PM

Good point - thanks David.