Fb request form guide


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Fb request form guide

  1. 1. Fb:request-form From Facebook Developers Wiki Description Creates a form that sends requests to the selected users. To send requests/invitations to multiple users, create one of these forms and include either an fb:multi-friend-selector or any combination of fb:multi-friend-input, fb:friend-selector and fb:request-form-submit. The form is submitted after the user confirms the sending of the request. If you want to invite only one friend, without making the user select from a list of friends, use the fb:request-form-submit tag within the fb:request-form tag, and make sure to set the appropriate attributes (uid, label) on the submit button to indicate that you are sending an invite to only one friend. In general, use fb:multi-friend-selector in a nearly full-page invitation interface where the user is intended to select a large number of people, and fb:friend-selector or fb:multi-friend-input in situations where the user is selecting a smaller number of users and you want to integrate it into the context of your own page. As a middle-ground alternative, you can use the fb:multi-friend- selector (condensed) for places where the user might select a medium-sized list of people without needing a full-page interstitial invitations interface. For developers using iframes, you cannot get the full flexibility of the fb:request-form system. However, you can still send requests using the Multi_friend_selector, or you can use the fb_force_mode parameter to render a particular canvas page with FBML. For developers wishing to utilize more form parameters, typical form input can be used with the attribute fb-protected="true" within any fb:request-form-submit tag. Attributes Required Name Type Description required type string The type of request or invitation to generate. This corresponds to the word that is displayed on the home page. For example, "event." content string The contents of the request or invitation to be sent. It should use FBML formatting that contains only links and the special tag <fb:req-choice url="" label="" /> to specify the buttons to be included in the request. Make sure that you properly encode this attribute. For example, use the PHP "htmlentities" function.
  2. 2. optional invite bool Set this to true if you want to send an invitation or false if you want to send a request. The difference between them is in the content that the user sees. (Default value is false.) action string The place where a user gets redirected after submitting the form through the fb:request-form-submit button or when they click Skip this Step. By default the user is directed to http://apps.facebook.com/yourapp/null. Note: This default behavior may not be preserved.[verify] method string Set it to either GET or POST, as you would with a form. POST Variables Required Name Type Description typeahead string The string containing any content the user typed into the multi- selector box. ids array A zero-based array containing all of the user IDs of the people the user invited. Examples Example FBML Invite Page <fb:fbml> <fb:request-form action="index.php" method="POST" invite="true" type="YOUR APP NAME" content="Your text goes here. <?php echo htmlentities("<fb:req-choice url="YOUR CANVAS URL" label="Add My Application"") ?> > <fb:multi-friend-selector showborder="false" actiontext="Invite your friends to use YOUR APP NAME."> </fb:request-form> </fb:fbml> Example Java Invite Page
  3. 3. Here is the FBML: <fb:request-form action="start.htm" method="POST" invite="true" type="nutshOt network" content="nutshOt network is the best place on Facebook for viewing, sharing and giving friends the highest quality nutshOts. Join me on the nutshOt network! <fb:req-choice url='http://www.facebook.com/add.php?api_key=<c:out value='${apiKey}' />' label='Check out the nutshOt network!' /> "> <fb:multi-friend-selector showborder="false" actiontext="Invite your friends to the nutshOt network." exclude_ids="<c:out value='${appUserFriends}' />" max="20" /> </fb:request-form> Here is the server side Java: protected Map referenceData(HttpServletRequest request) throws Exception { logger.info("InviteFriendsFormController.referenceData ..."); FacebookRestClient facebookRestClient = getFacebookUtils().getFacebookRestClient(request); //get the list of friends who are app users so they can be excluded from the invite page String appUserFriends = getFacebookUtils().getAppUsersFriendsString(facebookRestClient);
  4. 4. HashMap referenceData = new HashMap(); referenceData.put("appUserFriends", appUserFriends); referenceData.put("apiKey", PropertyUtils.getInstance().getPropertyValue("API_KEY")); getFacebookUtils().loadUrlData(referenceData); return referenceData; } You can see it in action at The nutshOt network Example PHP Invite Page <?php require_once('config.php'); require_once('init.php'); require_once('lib.php'); $user = $facebook->require_login(); // Get list of friends who have this app installed... $rs = $facebook->api_client->fql_query("SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = $user)"); $arFriends = ""; // Build an delimited list of users... if ($rs) { $arFriends .= $rs[0]["uid"]; for ( $i = 1; $i < count($rs); $i++ ) { if ( $arFriends != "" ) $arFriends .= ","; $arFriends .= $rs[$i]["uid"]; } } // Construct a next url for referrals $sNextUrl = urlencode("&refuid=".$user); // Build your invite text $invfbml = <<<FBML
  5. 5. You've been invited to join the PickPocket™ Guild! <fb:name uid="$user" firstnameonly="true" shownetwork="false"/> wants you to add PickPocket™ so that you can join <fb:pronoun possessive="true" uid="$user"/> wily band of thieves! <fb:req-choice url="http://www.facebook.com/add.php?api_key=$appapikey&next=$sN extUrl" label="Join the Guild!" /> FBML; ?> <fb:request-form type="PickPocket" action="index.php?c=skipped" content="<?=htmlentities($invfbml)?>" invite="true"> <fb:multi-friend-selector max="20" actiontext="Here are your friends who don't have PickPocket™. Invite them to play with you!" showborder="true" rows="5" exclude_ids="<?=$arFriends?>"> </fb:request-form>
  6. 6. Example Overloaded Form <fb:fbml> <fb:request-form method="POST" action="compare.php" content="some content" type=""
  7. 7. invite="false"> <input id="first_overloaded_id" type="hidden" fb_protected="true" value="first_overloaded_value" name="first_overloaded_name"/> <input id="second_overloaded_id" type="hidden" fb_protected="true" value="second_overloaded_value" name="second_overloaded_name"/> <div class="clearfix" style="padding-bottom: 10px;"> <fb:multi-friend-selector condensed="true" style="width:80%;" /> </div> <fb:request-form-submit /> </fb:request-form> </fb:fbml> Example ASP.NET Invite Page <p>Invite a friend to use this application... <fb:request-form action="default.aspx" method="POST" invite="true" type="Test App" content="You have been invited to the Test Example application. <% = Server.HtmlEncode("<fb:req-choice url="http://apps.facebook.com/test/default.aspx" label="OK" />") %> " > <fb:friend-selector showborder="false" actiontext="Invite your friends to use this application." /> <fb:request-form-submit /> </fb:request-form> </p> Example Python (Django + PyFacebook) Invite Page def invite_friends(request): #HTML escape function for invitation content. from cgi import escape facebook_uid = request.facebook.uid fql = "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='%s') AND has_added_app = 1" % facebook_uid
  8. 8. result = request.facebook.fql.query(fql) # Extract the user ID's returned in the FQL request into a new array. if result and isinstance(result, list): friends_list = map(lambda x: str(x['uid']), result) else: friends_list = [] # Convert the array of friends into a comma-delimeted string. exclude_ids = ','.join(friends_list) # Prepare the invitation text that all invited users will receive. content = """<fb:name uid="%s" firstnameonly="true" shownetwork="false"/> wants to invite you to play Online board games, <fb:req-choice url="%s" label="Add Online Gaming and Video Chat to your profile!"/> """ % (facebook_uid, request.facebook.get_add_url()) invitation_content = escape(content, True) return render_to_response('facebook/invite_friends.fbml', {'content': invitation_content, 'exclude_ids': exclude_ids }) Example Python (Django + PyFacebook) Invite Friends template <fb:request-form action="http://apps.facebook.com/livevideochat/?skipped=1" method="POST" invite="true" type="Online Games" content="{{ content }}"> <fb:multi-friend-selector max="20" actiontext="Here are your friends who haven't added Online Games and Live Video Chat to their profile. Invite them to play Games Online today!" showborder="true"
  9. 9. rows="5" exclude_ids="{{ exclude_ids }}"> </fb:request-form> Notes  Make sure to include whatever attributes you would normally include if you were creating a <form> tag, such as action and method, as mentioned above.  The fb:multi-friend-selector tag does not show up in Internet Explorer 6.[verify][I have IE 6 and it works fine]  The type attribute appears to have a hard limit of 20 characters. Anything else is truncated. Retrieved from "http://wiki.developers.facebook.com/index.php/Fb:request-form" Categories: Unverified statements | Articles needing screenshots | FBML tags