Creating a custom facebook fan page

A Facebook Page is a public Profile that enables information about business and products to be shared with Facebook users and the public. An user should be able to create one in a few minutes. This article explains how to add custom tabs to your Facebook page to make it do more. Here we explain how we built a carousel, navigation tabs, forms, etc on the Webdigi Facebook fan page.

Nutella Facebook fan page

What do you need to create custom Facebook fan pages?

The only thing you need is Static FBML created by Facebook, this is an application that you have to add to your page. You can add advanced functionality to your fan page using the Facebook Static FBML application. This application will add a tab to your Page in which you can render HTML or FBML (Facebook Markup Language) for enhanced Page customisation. You will be able to add more than one tab using this application. On our Facebook fan page, we have three pages created using this application: services, portfolio and contact.

What are the restrictions on Facebook ?

1) Facebook does not allow Javascript to run on load, an user action like a mouse click must be performed before Javascript can be run. You will notice this on the services tab of our Facebook fan page. The carousel mouse over works only after you click on one of the arrows.

2) You will need to use FBJS (Facebook Javascript). This provides the functionality we need to develop custom facebook pages. This is also to protect other users privacy at the same time and restrict Javascript features that can be abused.

3) Use <link href=”http://example.com/style.css” rel=”stylesheet” type=”text/css” /> if you want to use CSS on your Facebook fan page. This is to get the page to work correctly on Internet Explorer. The other browsers support the <style type=”text/css”> tag.

4) AJAX requests have a short timeout and these requests are proxied via Facebook. There are also limits on length of JSON replies, etc.

Creating tabs on the Facebook fan page using FBML and FBJS

FBJS is Facebook’s solution for developers who want to use JavaScript in their Facebook applications. FBJS DOM objects implement most of the same methods regular JavaScript objects implement including: appendChild, insertBefore, removeChild, and cloneNode. Properties like parentNode, nextSibling, src, href (and many many others) have been redefined as a couplet of getters and setters (getStyle : setStyle, getValue : setValue, getClassName : setClassName). Here is an example of a tab on a Facebook page.

apptabs

Creating a carousel on the fan page

FBJS exposes a powerful animation library which gives developers an easy way to improve their user interface with a line of code or two. All animations are CSS based, so a working knowledge of CSS will really help you out here. One of Facebook’s security restrictions are that Javascript will not be allowed onload of the page. The user must perform an action like clicking on a button, etc to begin Javascript code execution. This would mean that automated carousels; a carousel that starts rolling images by itself cannot be built into a Facebook fan page. This restriction also applies to pages with video, etc.

portfolio

Submitting a web form using AJAX

Creating a form for a fan page can be done using HTML. The AJAX support from facebook is interesting. All AJAX requests to the server you have under your control goes through facebook. If you have a tool monitoring the AJAX request, you will see that the form is actually being sent through to fbjs_ajax_proxy.php which in turn POST or GET the request to your server. The AJAX request can be sent using FBML in 3 steps:

var ajax = new Ajax();
ajax.responseType = Ajax.FBML;
ajax.post('http://example.com/ajax.php');

Creating Dialog boxes on Facebook

dialog

FBJS offers a variety of Dialog boxes: Confirmation boxes, Yes/No type, Dialog boxes with forms, Choice, etc. To create the above dialog, we just need the following one line of code

new Dialog().showMessage('Confirmation', 'The contact form has been submitted.');

Show me the code

Here are all the three code files that are in use for each of the three tabs on Facebook.

Contact Us tab (Containing form, AJAX submit and Dialog boxes) code

Portfolio tab (Carousel using FBJS Animation features) code

Services tab (Tabs within page, basic FBJS events) code

We hope this helps you cut short your search and gives you a head start in your quest to build custom tabs within Facebook pages. There are numerous resources out there that helped us understand FBJS and build this article. Do send us links to fan pages that you have built, looking forward to your comments.

Also read...

Comments

  1. Glad said on :

    Thanks for sharing the code and giving me a head start. I found a way to use AJAX bypassing Facebook central server (using FBJS LocalProxy) and hope it helps people who want to speed up requests.

    AJAX allows you to make three different types of requests. RAW, JSON, and FBML. For FBML, it is necessary that the request go through Facebook FBML proxy server so that Facebook can collect data and render the FBML. For RAW and JSON types, there is no reason to go through the Facebook central server. The Ajax object now has a new property useLocalProxy that lets you make direct calls to your app server. If you find yourself using Ajax often it is worth checking out this new functionality.

    This requires this file being placed in crossdomain.xml on your server, changes to FBML and using ajax.useLocalProxy=true. For more information google FBJS LocalProxy.

  2. Matthew FOrr said on :

    Most excellent! I’ve really enjoyed building a Facebook fanpage for my employer and have been procrastinating putting a Email newsletter signup on it. I finally got around to it today with inspiration from you guys.

    One note, the CSS that you guys use in your contact form is pretty broken in FF 3.5.2, apparently FB adds a lot of hidden input fields to any form element. I found that to fix this you need to create a class for you input, textarea, labels and etc. Hope that helps!

  3. Henrik Persson said on :

    very interesting, i’ve been a “fan” of nutella on fb for about a year or so, and never actually looked at their page.

  4. Destiny Islands said on :

    Really useful guide dude! So many people don’t know how to utilize Facebook, but reading your article and learning from your advice really helps. Thanks again!

  5. Pingback: How to Create a Cutsom Facebook Page with FBJS

  6. Jasper said on :

    Very interesting, thank you!

  7. Webling said on :

    Comes handy at the right time. Thank you!

  8. Danny said on :

    Very useful guide. Thank you.

    Can you call the Facebook API from a page? For example, can you provide a button that will update the user’s status when clicked (“is the biggest fan of [product]”).

  9. Pingback: How to create custom facebook fan page | blogfreakz.com

  10. Pingback: » Creating a custom facebook page – PHP, Web and IT stuff :: La Gaceta del Norte

  11. Pingback: What Do You Need to Create Custom Facebook Fan Pages? Webmove

  12. GrZeCh said on :

    Does someone faced issue that document.getElementById(‘name’) returns null?

  13. Kalesaray said on :

    very nice,Thank you.

  14. Loraine said on :

    Great works well.

  15. Brett Skinner said on :

    Very nice, thank you for sharing.

    Just managed to get my facebook contact page working with AJAX.

  16. Omares said on :

    Muchas gracias or Thanks a lot!!!!!!!!!! 😀

  17. Mansur said on :

    Thanks!! Helped a lot. Great Post guys!!!

  18. gf said on :

    Hi, could you maybe add the code from the contactus.php ? or just a simple code that sends email from this.. I copyed your codes and tested the thing and all the facebook stuff works great and easy to edit and modify, but i´m really stuck at what the contact.php should look like, i just found some very basic contact.php on about.com or something and that file is getting me no emails from the form and also it always gives me error messages on facebook 🙂

    But great and very helpfull tutorial 🙂

  19. Pingback: iLibrarian » Creating a Custom Facebook Fan Page

  20. Webdigi Blogger - iphp said on :

    Thanks for the wonderful feedback and to all the fans on our Facebook fan page!

    @gf, you are on the right track, you will be able to get all the details in the $_POST super global
    $_POST[‘name’]
    $_POST[’email’]
    $_POST[‘telephone’]
    $_POST[‘message’]. Do send us a link to your facebook fan page.

  21. Pingback: Really Useful Tutorials You Should Have Read in January 2010 Ajax Help W3C Tag

  22. felipe saavedra said on :

    muchas gracias, comenzaré a usarlo pronto.

    saludos,
    Felipe

  23. Pingback: Alusión (weekly) « Alusión…Llamada Virtual

  24. AJ said on :

    Are you able to stack the javascript portfolio somehow and make them click independently?

  25. Julián Landerreche said on :

    Thank you for this great tutorial and for sharing the .fbml examples. They were really helpful to understand the basics of Static FBML.

    I’ve already created a few custom tabs for a company’s FB Page, including a contact form processed by Swiftmailer library.
    I used 520px as width (it has been announced that FB Page canvas width will change to that width, eventually, right?).

    Thanks again!

  26. soledad said on :

    Hello! Great stuff guys! It’s really usefull!

    I’m having a problem with ajax.onerror function. If i don’t fill the fields, the “Sending ok” appears, and not the error message. I’m not sure if i need some particular variable in my php… can you help me please?

    Thank you so much in advance!!!

  27. Pingback: PHP, Web and IT stuff » Blog Archive » Google Analytics for Facebook Fan Pages

  28. Pingback: Usare Google Analytics con le Fan Pages di Facebook | maxzaglio.com

  29. Fran said on :

    Hi there

    It’s brilliant table – but I’ve got two questions – they might seem a little daft. Where do the email requests actually go to? And is there any way of clearing the table after the form has been sent?

    Many thanks
    Fran

  30. California Wedding Photographer said on :

    Thank you so much for sharing your FBJS animation code. I was able to modify it to create a very simple, but striking way to improve my photography fan page. You can see it here:

    facebook.com/embracelifephoto

    I appreciate your openness!

  31. Rob Q said on :

    I took your “portfolio” FBML code and dropped it in a fan page static FBML tab with the idea of testing, It worked!

    I’d like to second GF’s request for a copy of the script contactus.php for processing the emails – would that be possible? Awesome tutorial all around.

  32. iphp said on :

    @gf, @Rob, Thanks for your comments, I am glad it helped.
    Here is a PHP script that you can use on the server for contactus. Please make changes as necessary. Here is the link: pastebin.com/raw.php?i=0AE4khs2

  33. Pingback: JQueryin » Archive » » Overriding Facebook FBML Styling on a Canvas Page

  34. Pingback: How to Pimp Your Facebook Fan Page » CapeLinks Blog

  35. gill said on :

    Awesome guyz, jst wana thank u

  36. Dave W. said on :

    I am having the same issue as GrZeCh above, where my elements that are referenced by document.getElementById are returned as null to my processing script. Everything is working fine when I a default value is submitted in the contact form, but any user input doesn’t get passed through.

    Any help would be appreciated.

  37. Julián Landerreche said on :

    I’ve also added a contact form on a box, next to the Wall. 🙂
    The only limitation here seems to be that you can’t link to a CSS file, so you have to include the style rules inside a tag.

    You can check it here:
    facebook.com/cluster.efectos?v=wall

  38. saika said on :

    hey guys, is it possible to create facebook fan pages from PHP? I wanna create fan pages for my portal users using PHP code.

    Thanks in advance guys.

  39. Jani said on :

    Thanks for the great example. I’m trying to get the contact form to work at developers.facebook.com/tools.php?fbml I just copied your script and changed the form address to mine, but I keep on getting ‘An error has occurred while trying to submit.’ Any ideas why?

  40. js said on :

    I second Fran’s comment. Is there a way to clear the form after someone clicks on the “Okay”? OR second, is there a way a user can be redirected to another page after clicking on the Okay button?

    Thanks in advance!

  41. iphp said on :

    @js,@fran Clearing down the form is pretty easy to do for someone who understands Javascript. I am hoping someone who found this article useful will contribute. In the Javascript function submitAJAXForm() we need a document.getElementById(‘name’).setValue(”). This should be repeated for each of the fields. An easier method might be to use form.reset() if Facebook allows it!

  42. Rachel said on :

    Hi! Thanks for the article. Would you mind giving me some further assistance (or tips). I followed your instructions and the form seems to function, but I never receive the email.
    This is the link/page I am working on: (http://www.facebook.com/pages/Allen-TX/Home-Maintenance-Solutions-HMSRepair/105934849398?v=app_7146470109)
    (once I get it working I want it to be my default landing)
    And here is a link to my PHP script: (http://pastebin.com/KaYwxh77)
    I am new to php and I cannot figure out where or what is my error.

  43. Angela said on :

    Thanks so much for posting this! I was struggling with another form, then found this… and it’s great. Would be nice to know how to clear it after submit, but I’m content with it as is. Thanks again!

  44. Tracy A. Wehringer said on :

    question – I loved your code to create a form on FB, but what do I need to do to have the inbound emails come to me?

    Thanks, love your site
    Tracy

  45. Jani said on :

    Posting this again since it says awaiting for moderation…
    Thanks for the great example. I’m trying to get the contact form to work at developers.facebook.com/tools.php?fbml I just copied your script and changed the form address to mine, but I keep on getting ‘An error has occurred while trying to submit.’ Any ideas why?

  46. Omer Rosenbaum said on :

    Hi!
    I tried the contact form but it deoesn’t work. After filling my details and sending I get a massage that it was sent but receive no email.
    Should I change something in the contact form script? I just copied and pasted it in the FBML tab. Do I need to upload a file to my server that will do the action of sending?

  47. iphp said on :

    @Omer, @Rachel, You will need to have some PHP code running on your own server to send the data in an email submitted via the Facebook. This is a fairly trivial thing to setup for a PHP/web developer. You can try with the code posted on this page: pastebin.com/raw.php?i=0AE4khs2

  48. Clint said on :

    It looks great but I have the same question as Omer, what part of the code do I change so it comes to me?

    Thanks!

  49. Cullen Swanson said on :

    This is awesome, thanks for sharing! I will implement into all of our client’s websites now lol

  50. Paul said on :

    Hi there… a quick question.

    I followed your example, and it’s stunning. Really helped me a lot.

    Now a question. Is it possible to put in a few radio buttons?

    In my contact form, I need to ask for their age range, and I thought either a drop menu, or radio buttons would be easiest… but I can’t find any ANYWHERE.

    Please, if you have some little piece of magical code, you would help me so much…. have spent 48 hours googling to no avail.

    Thanks

  51. Paul said on :

    Hi there.

    What happened? My FBML page just dissapeared, or at least it seems to try and load then nothing else happens. I panicked, and thought I would go check your out… YOUR’S DOESN’T WORK EITHER!

    Go and try to see your portfolio tag… it endlessly loads.

    What happened?

  52. iphp said on :

    @Paul, Thanks for alerting us. This is now working. This was caused by Facebook making some changes. You can read more about it here bugs.developers.facebook.com/show_bug.cgi?id=9968 This was reported by another person on our Facebook fan page http://facebook.com/webdigi.

  53. Pingback: Building a Stellar Facebook Page to Attract Your Raving Fans and Customers | jirrajarra - Web 2.0 Technology Made Simple

  54. Pingback: Creating A Custom Facebook Fan Page - ChurchKreatives – A Community For Creative Christ Followers

  55. Ben said on :

    Hi im a small online company and i need the 1,2,3 hack steps to making a custom page for FB. I would also like to know where i even input the code on facebook to begin with….Can you point me in the right direction??

  56. Lucas H said on :

    Thank you so much for the contact form codes.

    Me and my friends are running a small online store, and it seems like the codes came in time for us….Great stuff~

  57. Tim said on :

    Thanks for the article! We have built a custom facebook page for our marketplace too – facebook.com/FlashScope 🙂 Check it out!

  58. Okg said on :

    How do I enter my e mail address? The form was submitted to the fan page but the messages don’t appear on my e mail.

    Thanks for this great post:)

  59. Amish said on :

    I am not Tech savvy and i dont know how to use AJAX or JAVAscript, is any other facebook application available which helps me to create my fan page ?

  60. adam said on :

    so how do you get the contact form to send to your own email?
    thank you

  61. Vince said on :

    Great info here, anyone available to help with the php to send in the form?

  62. Popiplo said on :

    Thanks for sharing the code, it is very useful. Great work!

  63. Suske said on :

    Good stuff. I do seem to get the email 3 times though. Is that just me?

  64. Suske said on :

    ah.. it’s a facebook thing, if you have your post destination URL return blank content then FB hits the page 3 times.

    However, if you have your page return with some sort of content it will only hit it once.

    I just added
    echo “dummy value”;
    to my PHP

  65. Dave Reeder said on :

    Very nice tutorial thanks, very useful, I shall produce my own facebook page when I launch my new site later in the year 🙂

  66. Alexey said on :

    Nice tutorial. Anyway I need to call Iframe on my FB page without clicking on a link.
    How can I do this? Maybe with onLoad event?

  67. Amit said on :

    I used the code and also created the PHP page on my server to collect the data which is working fine.. But major issue i have is with submitting the form.. When i submit the form, always the Onerror function is called whereas the data gets submitted 3 times.. What is the response data to be sent back fromt he server? Can u pls help me..

  68. matthew said on :

    where would I put the echo? I put it in the php and it doesnt ever send the email to me. Once I take away the echo, it allows the email to go through, but it sends three messages.

    Can anyone help with implimenting the reseting of the form?

  69. iphp said on :

    @Suske, thanks for posting your find. We use a separate script to send out email and it works fine.

    @matthew, I have updated the code here http://pastebin.com/raw.php?i=U3WGZNBY

    @Alexey, Unfortunately, Facebook does not give us an onload event. I think they dont want Facebook to be as messy as MySpace with onload music, etc.

  70. matthew said on :

    ok thanks that helps a lot. I was just putting the echo in the wrong place by mistake. PHP isnt my strong side. Neither is Java Script. Did anyone figure out how to reset the form?

Comments are closed.