Hello,

I have a problem in building an app for Facebook, and I think the problem is in the form in action.

It is a form script that I use that in index.php uses include the form.php. A fan gate is working well, with $ like_status, and the problem appears when the user submits the form that is only visible after giving the like.

After submitting it goes back in session, and returns the content of non-fan, ie, as if no like.

The link: https://apps.facebook.com/hoteldosado/

Please help me!
Thanks

The code: index.php

PHP Code:
<?php

//start session
session_start();

// Include all the output functions
require_once('form.php'); 

// populate input fields into the session using a sub-array
$_SESSION['myForm'] = $_POST;

require 
'facebook.php';

$facebook = new Facebook(array(
'appId' => '****',
'secret' => '****',
'cookie' => true
));

$signed_request $facebook->getSignedRequest();
$like_status $signed_request["page"]["liked"];

?>

<!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" />
<title>Passatempo Hotel do Sado</title>

<script type="text/javascript">
window.fbAsyncInit = function() {
FB.Canvas.setSize();
}
// Do things that will sometimes call sizeChangeCallback()
function sizeChangeCallback() {
FB.Canvas.setSize();
}
</script>
<link href="style.css" rel="stylesheet" type="text/css" />

<style>
      body {overflow:hidden;} /*This is handy for removing horizontal/vertical scrollbars as we won't need them if we autosize; */
</style>


</head>

<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/pt_PT/all.js#xfbml=1&appId=****";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/pt_PT/all.js#xfbml=1&appId=****";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div id="fb-root"></div>
<script src="https://connect.facebook.net/en_US/all.js"></script>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId : '****', //Your facebook APP here
      cookie : true // enable cookies to allow the server to access the session
    });
  }

  window.onload = function() {
    FB.Canvas.setAutoGrow(91);
  }
</script>
  
  
<div id="container">
    <div id="header"></div>
    <div id="clear"></div>
    <div id="headline">
      <h1><strong>Passatempo</strong> Fim de Semana de Praia</h1><div id="share"><div class="fb-send" data-href="https://apps.facebook.com/hoteldosado/"></div></div>
    </div>
    <div id="clear"></div>
    <div id="content">

  <?php if (($like_status)) { ?>
  <h2>Vem ai o tempo de praia. Nada melhor do que escolher  as praias da Arrábida, de Troia e da Comporta. </h2>
  <p>Quer ganhar um dos três fim-de-semanas com meia pensão que o Hotel do Sado e a RFM têm para lhe dar?</p>
  <p>Inscreva-se no passatempo e responda às questões que vamos colocar entre 27 e 31 de Maio. Quem responder correctamente, fica habilitado a um dos três fim-de-semanas. </p>
  <p><strong>Uma dica:</strong> a rapidez de resposta ajuda.
  
  <div id="formbox">
       
      <?php
        
// contact form
        
if (isset($_POST['submitted']) && ('true' == $_POST['submitted'])) { 
            
// checks if the form is submitted and then processes it
            
process_form(); 
            
        } else { 
            
// else prints the form
            
print_form(); 
        }    
        
?>
        
      </div>
      <?php } else { ?>
          <div class="fb-like" data-href="http://www.facebook.com/meonlinept" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>
      <?php ?>  
      
</div>
    <div id="clear"></div> 
   
  <div id="footer">
    <div id="edc"><a href="http://www.edc.pt"><img src="images/logoedc.png" width="25" height="15" border="0" title="EDC" alt="EDC" /></a>
        </div>
  </div>
  
</div>
    

<div id="fb-root"></div>
<script src="https://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '****',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
 
window.fbAsyncInit = function() {
FB.Canvas.setAutoResize();
}
</script>

<script>
FB.Event.subscribe('edge.create',
function(response){
top.location.href = 'http://www.facebook.com/****';
});
</script>

</body>
</html>
<?php session_destroy(); //unset session data ?>
The code: form.php

PHP Code:
<?php
//start session
session_start();

// prints form
function print_form(){
?><head>
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>

</head>

<form method="post" action="index.php" id="uploadform" enctype="multipart/form-data">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top" style="padding-bottom:5px;"><label for="namefrom"><span class="dados">Nome:</span></label></td>
        <td width="86%" valign="top" style="padding-bottom:5px;"><input name="namefrom" id="namefrom" type="text" class="textarea" value="<?= $_SESSION['myForm']['namefrom']; ?>" tabindex="1"/></td>
      </tr>
      <tr>
        <td valign="top" style="padding-bottom:5px;"><label for="emailfrom"><span class="dados">E-mail:</span></label></td>
        <td valign="top" style="padding-bottom:5px;"><input name="emailfrom" id="emailfrom" type="text" class="textarea" value="<?= $_SESSION['myForm']['emailfrom']; ?>" tabindex="2"/></td>
      </tr>
      <tr>
        <td valign="top" style="padding:0 15px 5px 0;"><label for="telemovel"><span class="dados">TelemÓvel:</span></label> </td>
        <td valign="top" style="padding-bottom:5px;"><input name="telemovel" id="telemovel" type="text" class="textarea" value="<?= $_SESSION['myForm']['telemovel']; ?>" tabindex="3"/></td>
      </tr>
  </table>
<input type="submit" name="submit" id="submit" value="INSCREVER" class="select2" tabindex="9"/><input type="hidden" name="submitted"  value="true" /></p>
</form>
<?php
}

// enquiry form validation

function process_form() {
    
// Read POST request params into global vars
    // FILL IN YOUR EMAIL
    
    
$namefrom trim($_POST['namefrom']);
    
$emailfrom trim($_POST['emailfrom']);
    
$telemovel trim($_POST['telemovel']);
    
    
    
// Thank you message
    
$thanksmessage="Inscrição efectuada com sucesso.";

    
$errors = array(); //Initialize error array
    

//check
    
if(empty($_POST['namefrom']) || empty($_POST['emailfrom'])){ 
        
$errors[]='Preencha o nome e o email';
    
        } else {

        if (!
eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$'stripslashes(trim($_POST['emailfrom'])))) {
            
$errors[]='Introduza um e-mail válido';
        } 
// if eregi
    
// if empty email
    


    
if (empty($errors)) { //If everything is OK

        
        // Headers
        /*    $headers .= 'Content-type: text/html; charset=ANSI' . "\r\n";  
            $headers = "From: $emailfrom";
            $headers2 .= 'Content-type: text/html; charset=ANSI' . "\r\n";  
            $headers2 = "From: non-reply@axis.com"; */
        
        // create a boundary string. It must be unique
        /*  $semi_rand = md5(time());
          $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; */

          // Add a multipart boundary above the plain message
          
$message.="De: $namefrom <br>
                    E-mail: $emailfrom <br>
                    Telemóvel: $telemovel <br>
                    <br><br><br>"
;


          
          
$mensagem2  "Email com sucesso";
    
       
       
        if (
is_uploaded_file($fileatt)) {
        
        }
        
        
        
// Send the completed message
        
        
$to "email@test.pt";
        
$subject "Passatempo";
        
$subject2 "Passatempo";
        
$headers "From: $emailfrom \r\n" .
        
"Reply-To: $emailfrom \r\n" .
        
"Content-type: text/html; charset=UTF-8 \r\n"
        
$headers2 "From: non-reply@hoteldosado.com\r\n" .
        
"Reply-To: non-reply@test.com \r\n" .
        
"Content-type: text/html; charset=UTF-8 \r\n";  

        
mail($emailfrom,$subject2,$mensagem2,$headers2);
        
        
$envs = array("HTTP_USER_AGENT""REMOTE_ADDR""REMOTE_HOST");
        foreach (
$envs as $env)
        
$message .= "$env: $_SERVER[$env]\n";
        
        if(!
mail($to,$subject,$message,$headers)) {
            exit(
"Não foi possível enviar a sua mensagem. Reporte o administrador da página.\n");
            echo 
"<meta http-equiv='refresh' content='1;URL=index.php'>";
        } else {
            echo 
'<div id="feedbackfinal"><strong>Obrigado!<br></strong>'$thanksmessage .'</div>';
            echo 
"<meta http-equiv='refresh' content='4;URL=index.php'>";
            unset(
$_SESSION['myForm']);
            
print_form();
            
        } 
// end of if !mail
        
    
} else { //report the errors
        
echo '<div id="feedbackerro">';
        foreach (
$errors as $msg) { //prints each error
                
echo "$msg\n";
            } 
// end of foreach
        
echo '</div>';
        
print_form();
    } 
//end of if(empty($errors))

// end of process_form()
?>