Contact Us
  • How to Load PHP Form-Validation Errors on a Facebook Custom Tab Form

    I recently built a PHP/MySQL-based sign-up form for a fan-gated page on Facebook. It tested perfectly when the page’s URL is accessed directly.

    However, when viewed and tested on Facebook (which places the page within an iFrame), the non-fan content is loaded whenever a validation error occurs, i.e., a required field isn’t filled in. So users would be left befuddled because the non-fan page invites them to “like” the page again and they have no idea that the info they just entered was invalid.

    So how did I get the fan-only content to display when the user fails to complete required fields, so that the user sees the form and the validation errors?

    I first looked into the conditional that loads the fan-gated page:

    if ($like_status) {
    echo "<!-- fan-gated content -->";
    } else {
    echo "<!-- non-fan content -->;

    It appears that I needed something more than the $like_status variable to load the fan-gated content in a validation-error scenario. PHP sessions (tutorial on PHP sessions) seemed to be the answer. Starting a session to set my own variable was what was needed. So right after the opening PHP tag at the top of the file, I placed this:


    I went ahead and added this variable in the conditional:

    if (($like_status) || isset($_SESSION['form'])) {
    echo "<!-- fan-gated content -->";
    else {
    echo "<!-- non-fan content -->";

    Voilà! The fan-only content now loads when a validation error is encountered.


    1. Guys, that’s exactly what I was searching for.

      But I have a problem using this: Even if we do not like the page, we have access to the hided part !

      Can someone please help me to fix this?

      my email:

      Many thanks !


    Speak Your Mind