如何使用HTML和php发布变量?

时间:2019-05-31 01:39:17

标签: html

我必须在confirmationpage.html上打印从checkoutpage.html收集的用户的名字,姓氏和电子邮件。

我使用过邮政方法,但我不知道它是否正确完成。

结帐页面(部分):

    <!DOCTYPE html>
    <html>
    <head>
    <title>Checkout page</title>
    </head>
    <body>
    <h1>Checkout page</h1>
    <form action="Confirmationpage.html" method="POST">
    <input type="text" name="fName" placeholder="First Name"><br>
    <input type="text" name="lName" placeholder="Last Name"><br>
    <input type="email" name="email" placeholder="Email"><br>
    <input type="number" name="phoneNumber" placeholder="Phone Number"><br>
    <input type="submit" value="Confirm">
    </form>
    </body>
    </html>

确认页(部分):

    <!DOCTYPE html>
    <html>
    <head>
    <title>Confirmation page</title>
    </head>
    <body>
    <h1>Confirmation page</h1>
    <h2>Order Confirmed!</h2>
    <?php
    // define variables and set to empty values
    $fName = $lName = $email = $phoneNumber = "";
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
      $fName = $_POST["fName"];
      $lName = $_POST["lName"];
      $email = $_POST["email"];
      $phoneNumber = $_POST["phoneNumber"];
      echo $fName . " " . $lName;
      echo $email;
    }
    
    function test_input($data) {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
    }
    ?>
    </body>
    </html>

我希望我的名字,姓氏和电子邮件会打印在确认页面上,并在结帐页面上收集信息。

0 个答案:

没有答案