【问题标题】:How to pass input value to href如何将输入值传递给href
【发布时间】:2017-08-16 08:00:10
【问题描述】:

我有一个带有 post 方法和一个文本框和按钮的表单来提交。

我可以使用$_POST 轻松获取值,但我希望能够将此值传递给链接。

textinput = 搜索词

链接 = index.php?search=search term

如果我只是将它加入到 href 中,我会得到 $search 的值未设置,因为 $search 被设置为 $_POST

我知道这是可能的,wowhead.com 就是一个例子,虽然 id 宁愿不使用 javascript,只使用 css html 和 php。

谢谢!

使用表单方法 get 有效,但它也将我的按钮值传递给 url

<form action="search.php" method="get">
    <table style="border:0px">
        <tr>
            <td style="border:0px">
                <input id="search" name="search" autocomplete="off" type="text" maxlength="32" style="width:350px;" />
            </td>
            <td style="border:0px">
                <input name="submit" type="submit" value="Search" style="font-size:16;padding:3px;" />
            </td>
        </tr>
    </table>
</form>

显示如下:

http://localhost/search.php?search=searchterm&submit=Search

我不想拥有&amp;submit=Search

通过更改修复

<input name="submit" type="submit" value="Search" style="font-size:16;padding:3px;" />

to(去掉名字标签)

<input type="submit" value="Search" style="font-size:16;padding:3px;" />

【问题讨论】:

  • 尝试使用 $_REQUEST 而不是 $_POST ;-)
  • 请提供一些代码

标签: php forms post hyperlink


【解决方案1】:

使用get方法

<form action="index.php" method="GET">
    <input type="search" name="search" />
    <input type="submit" name="submit" />
</form>

<form action="index.php" method="GET">
    <input type="search" name="search" />
</form>

在 php 中你通过$_GET['search']获取值

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-05-17
  • 2017-04-15
  • 1970-01-01
  • 2014-04-30
  • 2017-05-29
  • 1970-01-01
  • 1970-01-01
  • 2019-02-15
相关资源
最近更新 更多