how to post and get data with an html form in fb apps
I just created a simple facebook app. I would like to add a simple html form that posts values to the same file. I wrote the code below, but it doesn't work.
When I type something into the text box of the form and hit submit, the page reloads but it doesn't get any values.
I can't figure out how to post data to the fb app on a canvas page. I would be grateful if you could help me to fix my code. Thanks.
<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => '229924173724291',
'secret' => '79e2bdaaa52bb3b80ea2f5e4c0f20d3e',
));
$user = $facebook->getUser();
if ($user) {
$me = $facebook->api('/me');
} else {
$loginUrl = "https://w开发者_StackOverflowww.facebook.com/dialog/oauth?client_id=229924173724291&redirect_uri=https://apps.facebook.com/tnxkapp/&scope=publish_stream";
echo "<script>top.location.href=\"{$loginUrl}\"</script>";
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<? print($_POST[name]); ?>
<form action="https://apps.facebook.com/tnxkapp/" method="post">
<input type="text" name="name" value="<?php print($name); ?>" />
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
Post to your actual app URL http://yourdomain.com/appfolder not the apps.facebook.com. You're essentially trying to post info to facebook not your app with what your doing now.
精彩评论