【问题标题】:How to pass the value of a form to another form?如何将一个表单的值传递给另一个表单?
【发布时间】:2015-08-27 06:00:36
【问题描述】:

我有一项任务,我需要将页面中表单的值传递给另一个表单。我正在使用POST 方法来执行此操作,但它不起作用。我真的很感激一些帮助。

这是我正在使用的代码:

第一种形式 (form2.php)

<html>
    <head>
        <title>FORM</title>
    </head>
    <body>
        <form action="form3.php" method="post">
            Name:<input type="text" name="name">
            Address:<input type="text" name="address">
            <input type="submit" name="Submit" value="submit">
        </form>
    </body>
</html>

第二种形式 (form3.php)

<html>
    <head>
        <title>MY HOMEPAGE</title>
    </head>
    <body>
    <?php
        $x=$_POST['name'];
        $y=$_POST['address'];

    echo $x;
    echo $y;

    ?>
    </body>
</html>

【问题讨论】:

  • 您的表格看起来很不错。你遇到了什么问题。
  • 你的问题很不清楚。请详细解释并分享您的第二个表单代码
  • 看起来应该可以了,请问有什么问题?
  • 检查你的表单名称 Form3.php 和你的
    不一样

标签: php html forms


【解决方案1】:

乍一看,您的代码似乎还不错。您错过了一些 次要 的事情,尽管它们通常不会阻止您获得输出。但为了确定起见,我已经整理了代码并为每个 POST 变量添加了一个测试。

尝试以下方法,看看是否有效。

第一种形式 (form2.php)

<html>
    <head>
        <title>FORM</title>
    </head>
    <body>
        <form action="form3.php" method="POST">
            Name:<input type="text" name="name" />
            Address:<input type="text" name="address" />
            <input type="submit" name="submit" value="submit" />
        </form>
    </body>
</html>

第二种形式 (form3.php)

<html>
    <head>
        <title>MY HOMEPAGE</title>
    </head>
    <body>
    <?php
        if(isset($_POST['submit']))
        {
            if(isset($_POST['name']))
            {               
                $x=$_POST['name'];
            }
            if(isset($_POST['address']))
            {               
                $y=$_POST['address'];
            }
        }
        echo $x;
        echo $y;
    ?>
    </body>
</html>

这是我添加到您的代码中的内容:

  1. 关闭form2.php 中打开的input 标签。
  2. 添加了isset 以检查POST 数据是否在form3.php 文件中接收。
  3. isset 添加到所有变量(在本例中为nameaddress)以检查它们是否被接收。

【讨论】:

    【解决方案2】:

    您使用的是linux环境,表单操作(form3.php)和文件名(Form3.php)不一样。在 linux 环境中,这些是区分大小写的。请使用相同大小写的操作 uri 和文件名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-01
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多