如何在php中将值从一个页面传递到另一个页面

时间:2016-02-29 11:37:28

标签: php jquery

我有两页,第一页是 customerdetail.php ,第二页是 package.php 。我必须将数据从customerdetail.php传递给package.php。有三种输入类型


customerdetail.php

<div>
  <input type="text" name="name" id="name" placeholder="Name" required/><br/><br/>
  <input type="text" name="Email" id="email" placeholder="Email" required/><br/><br/>
  <select id="item" class="dropdown">
    <option value="">Select</option>
    <option value="1" selected>1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
  </select>
  <input type="date" name="Date" id="name" placeholder="Date" required/><br/><br/>
</div>

<小时/>   package.php中的预期输出

名称
电子邮件
3
日期

1 个答案:

答案 0 :(得分:1)

您好,您可以使用POST方法将数据发送到另一页。

    <div>
<form method="POST" action="package.php" id="myform">
  <input type="text" name="name" id="name" placeholder="Name" required/><br/><br/>
  <input type="text" name="Email" id="email" placeholder="Email" required/><br/><br/>
  <select id="item" name="select" class="dropdown">
    <option value="">Select</option>
    <option value="1" selected>1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
  </select>
  <input type="date" name="Date" id="name" placeholder="Date" required/><br/><br/>
</form>
<div id="Result"></div>
</div>

    <script>
$(document).ready(function(e) {
    $("#myform").submit(function(e) {

        $.ajax({
               type: "POST",
               url: package.php,
               data: $("#myform").serialize(), 
               success: function(data)
               {
                   $('#Result').html(data); 
               }
             });

        e.preventDefault(); // avoid to execute the actual submit of the form.
    }); });
    </script>

AND IN package.php php使用下面的代码

$name =$_POST['name'];
$email = $_POST['email'];
$select = $_POST['select'];
$date= $_POST['Date'];
echo($name. "<br/>".$email. "<br/>".$select. "<br/>".$date);