开发者

Signed request not available in Facebook app on submitting form?

开发者 https://www.devze.com 2023-02-21 16:59 出处:网络
I am developing a Facebook application for use on page. It\'s essential a page with a web form that then creates a database record form the submitted data. Nothing too complex. The complexity comes wh

I am developing a Facebook application for use on page. It's essential a page with a web form that then creates a database record form the submitted data. Nothing too complex. The complexity comes when I try to differentiate between the sites when handling the post data. This is what I have:

<?php
require_once('../lib/facebook.php');
$facebook = new Facebook(array(
    'appId' => 'xxxxxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
switch ($signed_request['page']['id']) {
    case '144778562245193':
        define('SITE_ID', '3');
        define('SITE', 'UK Boxing Events');
        define('DOMAIN', 'ukboxingevents.com');
        define('BODY_CLASS', 'boxing');
    break;
    case '147183265335890':
        define('SITE_ID', '1');
        define('SITE', 'UK Wrestling Events');
        define('DOMAIN', 'ukwrestlingevents.com');
        define('ANALYTICS_ID', 'UA-xxxxxxx-xx');
        define('BODY_CLASS', 'wrestling');
    break;
    case '157856417600021':
        define('SITE_ID', '2');
        define('SITE', 'UK MMA Events');
        define('DOMAIN', 'ukmmaevents.com');
        define('BODY_CLASS', 'mma');
    break;
    default:
        die('Invalid page.');
    break;
}
if (isset($_POST['add_event'])) {
    // submit handler; writes to database
}
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Add Event</title>
  </head>
  <body>
    &l开发者_开发百科t;form action="" method="POST" id="add_event_form">
      ...
    </form>
  </body>
</html>

The page displays fine on the individual applications, as can be seen at http://www.facebook.com/ukwrestlingevents?sk=app_162023107185208. However, when I submit the form I get the "Invalid page." output as is the default case in my switch statement; as though there is no signed request present when a form is submitted, even though I thought the default request method used by Facebook was indeed POST and not GET.

Any ideas?


This is just an educated guess, but I think you must include the signed request as a hidden field in order to pass it on after you POST the form...

So:

<input type="hidden" name="signed_request" value="<?php print htmlentities($_REQUEST['signed_request']); ?>">

...should work...


If you type your page name inside the action="" method the form will be posted inside to your php page not the facebook page that you view from your browser.

0

精彩评论

暂无评论...
验证码 换一张
取 消