Creating a custom facebook fan page

Posted by iphp on Jan 11, 2010 in Facebook, Web, javascript |

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

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

Tags: , ,

37 Comments

Glad
Jan 13, 2010 at 11:13 am

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.


 
Matthew FOrr
Jan 13, 2010 at 9:07 pm

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!


 
Henrik Persson
Jan 14, 2010 at 12:31 am

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


 
Destiny Islands
Jan 14, 2010 at 3:15 am

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!


 
How to Create a Cutsom Facebook Page with FBJS
Jan 15, 2010 at 10:37 am

[...] users and the public. An user should be able to create one in a few minutes. This article “Creating a Custom Facebook Page” explains how to add custom tabs to your Facebook page to make it do more. He has explained how [...]


 
Jasper
Jan 15, 2010 at 11:51 am

Very interesting, thank you!


 
Webling
Jan 15, 2010 at 6:54 pm

Comes handy at the right time. Thank you!


 
Danny
Jan 15, 2010 at 9:50 pm

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]“).


 
How to create custom facebook fan page | blogfreakz.com
Jan 16, 2010 at 4:56 am

[...] this tutorial we will need Static FBML created by Facebook, this is an application that you have to add to your [...]


 
» Creating a custom facebook page – PHP, Web and IT stuff :: La Gaceta del Norte
Jan 16, 2010 at 4:34 pm

[...] Visitar enlace [...]


 
What Do You Need to Create Custom Facebook Fan Pages? Webmove
Jan 18, 2010 at 2:30 pm

[...] Link: webdigi.co.uk [...]


 
GrZeCh
Jan 20, 2010 at 4:03 pm

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


 
Kalesaray
Jan 23, 2010 at 3:26 pm

very nice,Thank you.


 
Loraine
Jan 23, 2010 at 3:27 pm

Great works well.


 
Brett Skinner
Jan 24, 2010 at 2:39 am

Very nice, thank you for sharing.

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


 
Omares
Jan 24, 2010 at 11:51 pm

Muchas gracias or Thanks a lot!!!!!!!!!! :D


 
Mansur
Jan 28, 2010 at 9:45 pm

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


 
gf
Jan 30, 2010 at 1:13 am

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 :)


 
iLibrarian » Creating a Custom Facebook Fan Page
Feb 1, 2010 at 4:27 pm

[...] folks at Webdigi have posted a tutorial for Creating a Custom Facebook Fan Page on their PHP, Web and IT stuff blog. This detailed guide provides step-by-step instructions and [...]


 
Webdigi Blogger - iphp
Feb 3, 2010 at 5:52 pm

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.


 
Really Useful Tutorials You Should Have Read in January 2010 Ajax Help W3C Tag
Feb 11, 2010 at 8:33 am

[...] Creating a Custom Facebook Fan Page January 11th, 2010 Site: PHP Web and IT Stuff [...]


 
felipe saavedra
Feb 11, 2010 at 2:13 pm

muchas gracias, comenzaré a usarlo pronto.

saludos,
Felipe


 
Alusión (weekly) « Alusión…Llamada Virtual
Feb 14, 2010 at 12:37 am

[...] » Creating a custom facebook fan page – PHP, Web and IT stuff [...]


 
AJ
Feb 16, 2010 at 9:25 pm

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


 
Julián Landerreche
Feb 19, 2010 at 3:19 pm

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!


 
soledad
Feb 21, 2010 at 6:00 pm

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


 
PHP, Web and IT stuff » Blog Archive » Google Analytics for Facebook Fan Pages
Feb 22, 2010 at 5:25 pm

[...] If you don’t have a Facebook fan page yet, visit our tutorial for code and help on creating customised Facebook fan pages. [...]


 
Usare Google Analytics con le Fan Pages di Facebook | maxzaglio.com
Feb 22, 2010 at 10:15 pm

[...] If you don’t have a Facebook fan page yet, visit our tutorial for code and help on creating customised Facebook fan pages. [...]


 
Fran
Feb 24, 2010 at 12:42 pm

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


 
California Wedding Photographer
Mar 1, 2010 at 2:06 am

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!


 
Rob Q
Mar 2, 2010 at 10:13 pm

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.


 
iphp
Mar 3, 2010 at 7:55 am

@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


 
JQueryin » Archive » » Overriding Facebook FBML Styling on a Canvas Page
Mar 4, 2010 at 11:18 pm

[...] and would still like to utilize a canvas page, I highly suggest you read the article entitled Creating a Custom Facebook Page as it guides you through all the steps necessary to getting a FBML page up and running with minimal [...]


 
How to Pimp Your Facebook Fan Page » CapeLinks Blog
Mar 8, 2010 at 12:38 am

[...] Creating a custom facebook fan page Extending Facebook Static FBML Tabs with Dynamic Content [...]


 
gill
Mar 8, 2010 at 12:45 am

Awesome guyz, jst wana thank u


 
Julián Landerreche
Mar 9, 2010 at 1:27 pm

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


 
saika
Mar 13, 2010 at 9:31 am

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.


 

Reply

Copyright © 2010 PHP, Web and IT stuff All rights reserved. PHP Web development in London.