phpfacebookformspostfacebook-canvas

Accessing POST data in Facebook canvas app


I've got a simple form in my canvas / iframe Facebook app, and I'm trying to pass along the values as POST. Now from reading all about this all over S.O. and FB's latest docs, as I understand it, all data send via a POST form can be accessed on the receiving end from the $_REQUEST object.

I also read on another thread on S.O. that in order for POST forms to work you need to pass along an input named "signed_request" with the value as the current signed_request (I have the signed request working ok otherwise...all login and authentication stuff working fine). This isnt mentioned anywhere in the official FB docs.

So my problem is that all that comes back in the $_REQUEST object is the signed request, and a bunch of other session stuff. My form inputs are nowhere to be found.

The only way I can read them is to set the method of the form to "REQUEST" which isn't even a real form method. But then it takes all of my inputs and sends them as GET args in the URL. Horrible. Here's a sample page from my canvas app with just a form i'm using to try to debug (leaving out all the authentication stuff):

<form enctype="application/x-www-form-urlencoded" method="POST" target="_top" id="my_form" action="https://apps.facebook.com/myfakeapp/form_test.php">
<input type="text" name="test1" value="58" />
<input type="text" name="test2" value="123" />
<input type="text" name="test3" value="434" />
<input type="text" name="test4" value="645" />
<input type="text" name="signed_request" value="<? echo $_REQUEST['signed_request']; ?>">
<input value="Submit Answers" type="submit">
</form>

The FB docs are confusing as some of it refers to this beta migration mode they had for older apps dealing with POST requests for canvas apps.


Solution

  • You are combining two separate techniques...the purpose of submitting a form with target=_top and action=apps.facebook.com/xxx is to get Facebook to automatically send the signed_request parameter. If you are sending it yourself, you should use your page's "external" address as the action and leave the target attribute off. By using target=_top, you are reloading the entire framework and sending your form data to Facebook, which of course ignores it.