简体   繁体   中英

Form not passing values on POST (popup box)

My form is not passing any values when I submit it. I am not too sure what is wrong with it. Can anyone spot my mistake(s)?

PHP code:

<?
$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>

尝试将<form action="poilist.php" method="post">放在任何输入(包括您的复选框)之前。

If this PHP page is named poilist.php then your $_POST variables should be set. Try removing the action attribute on the form since you are submitting back to the same page (If you don't specify an action, the form will submit back to the same page).

However, as @jNull noted, your check boxes will not be included in the post data unless they are part of the form being submitted.

PS. In this example you are missing your opening <?php tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM