1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Custom Facebook Tab and Form Validator Php

Discussion in 'Facebook API' started by JhonBau, Jul 30, 2013.

  1. #1
    Hope you're good!
    Having troubles using a Facebook Custom Tab. I want to create a Tab that display a form for people who like the page and an image for people doesn't like the page.
    That works perfectly. But when pushing the SEND button, I got a blank page. I read herehttp://www.hyperarts.com/blog/getting-facebook-to-load-php-validation-errors-on-a-sign-up-form/ that I had to use this:
    session_start();
    $_SESSION['form']='visited';
    PHP:
    With the condition:
    if (($like_status) || isset($_SESSION['form'])) {
    echo "<!-- fan-gated content -->";
    }
    else {
    echo "<!-- non-fan content -->";
    }
    PHP:
    The errors (echo) works and writing in the DB works well too but ANYONE can see the form. Even if they do not like the page.
    If anyone can help me please let me know. I'll be super happy!
    Here is the code:
    <?
    // Parametres mySQL
    $sql_serveur = "localhost"; // Serveur mySQL
    $sql_base = "xxxxxx"; // Base de donnees mySQL
    $sql_login = "xxxxxxxxx"; // Login de connection a mySQL
    $sql_password = "xxxxxxxxxx"; // Mot de passe pour mySQL
    // Connection au serveur mySQL
    @mysql_connect($sql_serveur, $sql_login, $sql_password) or die("Error connecting to the server");
    @mysql_select_db($sql_base);
     
    mysql_query("SET NAMES 'utf8'");
     
    session_start();
    $_SESSION['form']='visited';
     
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="style.css" rel="stylesheet" type="text/css">
    <title>BSF CONTEST</title>
     
    </head>
     
    <body>
    <?php
     
    $request = $_REQUEST["signed_request"];
    list($encoded_sig, $load) = explode('.', $request, 2);
    $fbData = json_decode(base64_decode(strtr($load, '-_', '+/')), true);
     
    if (!empty($fbData["page"]["liked"]) || isset($_SESSION['form']))
    { ?>
    <div class="wrapper">
     
        <img src="img/bg.jpg" alt="bg" width="800" />
        <div id="left">
        <h1>Brussels Summer Festival Contest</h1>
            <p>Try to <span class="bold">WIN</span> an exclusive trip to New York for 2 persons offered by <span class="bold">Brussels Airlines</span>!<br /><span class="petit gris">Winners will be notified by email</span><br /><span class="petit gris">By participating in this contest, each entrants agrees that BSF may contact them for information about the Brussels Summer Festival.</span><br /><br />Good luck!!</p><br />
        <h1>Informations</h1>
            <p>
                <span class="bold">WHERE:</span> Brussels<br>
                <span class="bold">WHEN:</span> 09 > 18.08.2013<br>
                <span class="bold">PRESALE:</span> 40€<br>
            </p>
            <img src="img/Logo-bsf.png" alt="Logo-bsf" width="300" height="239" />
        </div>
        <div id="right">
        <h2>Participate</h2>
            <?php
                if($_POST['posted']==1) {
                  $nom = $_POST['nom'];
                  $prenom = $_POST['prenom'];
                  $email = $_POST['email'];
                  $tel = $_POST['tel'];
                  $question1 = $_POST['question1'];
                  $question2 = $_POST['question2'];
                  $question3 = $_POST['question3'];
                  $date = date("Y-m-d H:i:s");
     
     
     
     
                  // vÈrification des donnÈes
                  if(empty($nom)) {
                        $error[] = "The <b>name</b> is empty !";
                  }
                  if(empty($prenom)) {
                        $error[] = "The <b>last name</b> is empty !";
                  }
                  if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                        $error[] = "The <b>email</b> is empty !";
                  }             
                  if(!empty($tel)) {
                      if (!preg_match("#^(0|\+32)[1-9]\d{8}$#", $tel)) {
                            $error[] = "The <b>phone number</b> est empty or wrong format !";
                      }
                  } 
                  if (empty($error)) {
                        mysql_query("INSERT INTO concours (
                        name,
                        lastname,
                        email,
                        tel,
                        question1,
                        question2,
                        question3,
                        soiree,
                        date)
     
                        VALUES (
                        '".$_POST['nom']."',
                        '".$_POST['prenom']."',
                        '".$_POST['email']."',
                        '".$_POST['tel']."',
                        '".$_POST['question1']."',
                        '".$_POST['question2']."',
                        '".$_POST['question3']."',
                        '".$_POST['soiree']."',
                        '".$date."'
                        )");
                        if(empty($error)){
                            echo "<p class='send'>Thanks to participate.";
                        }
                        else {
                            echo "<p class='error'>We got a problem. Try again </p>";
                        }
                    }
                    else {
                        echo '<p class="error">';
     
                        foreach ($error as $item) {
                            echo ''.$item.'<br>';
                        }
     
                        echo '</p>';
                    }
                }
                ?>
            <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
                First Name *<br />
                <input class="form" name="nom" /><br />
                Last Name *<br />
                <input class="form" name="prenom" /><br />
                Address e-mail *<br />
                <input class="form" name="email" /><br />
                Phone number<br />
                <input class="form" name="tel"/><br />
                What is your favorite group in the line up? <br />
                <input class="form" name="question1"/><br />
                What group would you like to see at the Brussels Summer Festival?<br />
                <input class="form" name="question2"/><br />
                How many people would attempt the BSF this year?<br />
                <input class="form" name="question3"/><br />
                <input type="hidden" value="1" name="posted" />
                <input type="hidden" value="BSF" name="soiree" />
                <input type="submit" value="SEND" class="sendbtn" />
            </form>
        </div>
     
     
     
    </div>
     
    <?php } else { ?>
    <div class="like">
        <img src="unlike.jpg" alt="like_superfit"/>
    </div>
    <?php } ?>
     
     
    <div id="fb-root"></div>
    <script type="text/javascript">
                window.fbAsyncInit = function() {
                    FB.init({
                        appId: '686278404719563',
                        cookie: true,
                        xfbml: true,
                        oauth: true
                    });
                    FB.Canvas.setAutoGrow(true);
                };
                (function() {
                    var e = document.createElement('script'); e.async = true;
                    e.src = document.location.protocol +
                        '//connect.facebook.net/en_US/all.js';
                    document.getElementById('fb-root').appendChild(e);
                }());
    </script>
     
    </body>
     
    </html>
    PHP:

     
    JhonBau, Jul 30, 2013 IP
  2. JhonBau

    JhonBau Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    I Also tried this:
    <?
    session_start();
    $_SESSION['form']='visited';
     
    require 'facebook.php';
     
    $app_id = "MY APP ID";
    $app_secret = "MY APP SECRET";
    $facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true
    ));
     
    $signed_request = $facebook->getSignedRequest();
     
    $page_id = $signed_request["page"]["id"];
    $page_admin = $signed_request["page"]["admin"];
    $like_status = $signed_request["page"]["liked"];
    $country = $signed_request["user"]["country"];
    $locale = $signed_request["user"]["locale"];
     
     
    if (($like_status) || isset($_SESSION['form'])) {
    echo "You like us";
    }
    else {
    echo "You don't like us yet";
    }
    ?>
    PHP:

    But I always see: "You like us"

    Many Thanks Guys !
     
    JhonBau, Jul 30, 2013 IP