简体   繁体   中英

Signed request not available in Facebook app on submitting form?

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>
    <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...

如果您在action =“”方法中键入您的页面名称,表单将被发布到您的php页面内,而不是您从浏览器中查看的Facebook页面。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM