【问题标题】:Send post form to the same page using php or html only仅使用 php 或 html 将帖子表单发送到同一页面
【发布时间】:2014-03-07 20:06:18
【问题描述】:

我只能使用 php 和 html 来做到这一点。 我正在尝试将文本框的输入传递给 URL。像这样的东西?输入=

页面将是相同的。

<form method='post' action="">
        <input type="text" name="input">
        <a href="http://example.com?input="<?php echo $_POST['input'] ?>><input type="submit" value="Submit"></a>
    </form>

【问题讨论】:

  • 不就是你想要的吗?
  • ?input= 需要 GET 方法。

标签: php forms post get submit


【解决方案1】:

如果您希望值在 url 中,您需要更改表单的获取方法

<form method="get" action="">

这将使您的网址看起来像http://mydomain.com/index.php?input=something。像这样在 URL 中传递的所有值都可以通过 $_GET 访问。

<?PHP
  echo $_GET['input'];
?>

你不需要锚标签,因为你有它。只需更改表单将导致表单按照您的需要提交。

<form method='get' action="">
    <input type="text" name="input">
    <input type="submit" value="Submit">
</form>

【讨论】:

    【解决方案2】:

    如果您想在 url 中附加所有表单输入,那么您应该使用 get 表单方法。 而且你不应该使用锚标签,因为它似乎没有意义。

    所以你的表格应该是这样的:

    <form method='get' action="">
            <input type="text" name="input">
            <input type="submit" value="Submit">
        </form>
    

    提交表单后,您的网址将如下所示:

    http://yousite.com/this_page?input=typed_value
    

    您可以使用全局 $_GET$_REQUEST 访问您的 purl 参数(例如 $_REQUEST['input']

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多