表单不在POST(弹出框)上传递值

时间:2015-11-18 19:04:59

标签: php jquery html mobile

我提交时,我的表单没有传递任何值。我不太确定它有什么问题。谁能发现我的错误?

PHP代码:

<?
$name = $_POST["name"];
$email = $_POST["email"];

$favouriteList = array("level_1","level_2","level_3","level_4","level_5",
"level_6","level_7","level_8","level_9","level_10","level_11","level_12",
"level_13","level_14","level_15","level_16","level_17","level_18", );

// if is not checked, zero out
if (!isset($_POST['checkBoxOne']))   {  $favouriteList[0] = ""; }
if (!isset($_POST['checkBoxTwo']))   {  $favouriteList[1] = ""; }
if (!isset($_POST['checkBoxThree'])) {  $favouriteList[2] = ""; }
if (!isset($_POST['checkBoxFour']))  {  $favouriteList[3] = ""; }
if (!isset($_POST['checkBoxFive']))  {  $favouriteList[4] = ""; }
if (!isset($_POST['checkBoxSix']))   {  $favouriteList[5] = ""; }
if (!isset($_POST['checkBoxSeven'])) {  $favouriteList[6] = ""; }
if (!isset($_POST['checkBoxEight'])) {  $favouriteList[7] = ""; }
if (!isset($_POST['checkBoxNine']))  {  $favouriteList[8] = ""; }
if (!isset($_POST['checkBoxTen']))   {  $favouriteList[9] = ""; }
if (!isset($_POST['checkBoxEleven'])){  $favouriteList[10] = "";}

/*$message = <<<EMAIl Hello $to. Your favourite POI list is : $favouriteList EMAIL;*/

$header = 'blabla@gmail.com';
$to = '$email';
$subject = 'Favourite POI List - Ghost Hunter Game';
$message = " Hello " . $name . "<br/>" . "Your favourite POI list is:" . "<br/>" . print_r(array_values($favouriteList));
mail($to, $subject, $message, $header);

if($_POST) {
  if($name == '' || $email == ''){
    $emailMsg = "Please complete the form with your name and your email.";
  }
  else {
    mail($to, $subject, $message, $header);
    $emailMsg = "Email sent successfully.";
  }
}
?>

HTML code:

<!DOCTYPE html>
<html lang="en">
  <head>
      <meta charset="utf-8"/>
      <title> Ghost Hunter </title>
      <link rel="icon" href="../img/ghost.png" type="image/x-icon">
      <meta name="viewport" content="width=device-width, intial-scale=1"/>
      <!-- JQUERY MOBILE CSS -->
      <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
      <!-- Local CSS -->
      <link rel="stylesheet" href="../css/poilist.css">
      <!-- JQUERY MOBILE - Place here to be overwritten by local js -->
      <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
      <script type="text/javascript" src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
      <!-- LOCAL JS -->
      <script src="../js/poilist.js"></script>
  </head>
  <body>
      <div data-role="page" id="poilist" data-theme="b">

        <div data-role="header">
          <h3> Choose level </h3>
          <a href="home.html"  data-icon="home" data-iconpos="notext" data-transition="slideup"></a>
          <a href="#sendEmail" data-icon="mail" data-iconpos="notext" data-transition="flip" data-position-to="window" data-rel="popup"> Send POI </a>
        </div> <!-- header -->

        <div data-role="content">

        <div id="emailMessage">
          <p id="emailMsg"> <?php echo $name; ?> </p>
        </div>

        <div data-role="navbar">
          <ul>
            <li><a href="level1.html" data-role="button" data-inline="true" data-transition="slide"> Level 1 </a></li>
            <li><input type="checkbox" id="checkBox_lvl1"/></li>
          </ul>
          <ul>
            <li><a href="level2.html" data-role="button" data-inline="true" data-transition="slide"> Level 2 </a></li>
            <li><input type="checkbox" id="checkBox_lvl2"/></li>
          </ul>
          <ul>
            <li><a href="level3.html" data-role="button" data-inline="true" data-transition="slide"> Level 3 </a></li>
            <li><input type="checkbox" id="checkBox_lvl3"/></li>
          </ul>
          <ul>
            <li><a href="level4.html" data-role="button" data-inline="true" data-transition="slide"> Level 4 </a></li>
            <li><input type="checkbox" id="checkBox_lvl4"/></li>
          </ul>
          <ul>
            <li><a href="level5.html" data-role="button" data-inline="true" data-transition="slide"> Level 5 </a></li>
            <li><input type="checkbox" id="checkBox_lvl5"/></li>
          </ul>
          <ul>
            <li><a href="level6.html" data-role="button" data-inline="true" data-transition="slide"> Level 6 </a></li>
            <li><input type="checkbox" id="checkBox_lvl6"/></li>
          </ul>
          <ul>
            <li><a href="level7.html" data-role="button" data-inline="true" data-transition="slide"> Level 7 </a></li>
            <li><input type="checkbox" id="checkBox_lvl7"/></li>
          </ul>
          <ul>
            <li><a href="level8.html" data-role="button" data-inline="true" data-transition="slide"> Level 8 </a></li>
            <li><input type="checkbox" id="checkBox_lvl8"/></li>
          </ul>
        </div> <!--navbar-->
      </div> <!--content-->

      <div data-role="popup" id="sendEmail">
        <!-- <a href="#" data-rel="back" data-role="button" data-icon="delete" data-iconpos="right" data-theme="b"></a> -->
        <form action="poilist.php" method="post">
          <h3> Send your Favourite Point of Interest </h3>
          <label for="name1 ">Name:</label>
          <input type="text"  placeholder="Your name"          name="name"  id="name1"/>
          <label for="email1">Email:</label>
          <input type="email" placeholder="youremail@gmail.com" name="email" id="email1"/>
          <input type="submit" id="submit" value="Send email">
        </form>
      </div> <!--popup-->

    </div> <!--page-->
  </body>
</html>

2 个答案:

答案 0 :(得分:0)

尝试在{em>任何输入之前添加<form action="poilist.php" method="post">,包括你的cheakboxes。

答案 1 :(得分:0)

如果此PHP页面名为poilist.php,则应设置$_POST个变量。尝试删除表单上的action属性,因为您要提交回同一页面(如果您没有指定操作,则表单将提交回同一页面)。

但是,正如@jNull所指出的那样,您的复选框不会包含在帖子数据中,除非它们是提交表单的一部分。

PS。在此示例中,您错过了开始<?php标记。