【问题标题】:PHP Send query string with buttonPHP 用按钮发送查询字符串
【发布时间】:2012-01-08 10:20:52
【问题描述】:

我有一个用于搜索产品的表单,该表单将在每个页面中显示。单击搜索按钮时,它将重定向到 search.php 页面。我想在单击按钮时发送一个带有搜索文本框内容的查询字符串(参数)。表单的代码很简单,但这里是:

<form method="post" action="search.php">
    <input type="text" id="txtSearch" name="txtSearch" class="searchInput" value="" />
    <input type="submit" id="btnSubmit" name="btnSubmit" value="Search" ?>'" />
</form>

我希望点击它时会重定向到 search.php?q=txtSearch。谢谢。

【问题讨论】:

    标签: php html get


    【解决方案1】:

    在表单元素上将“POST”更改为“GET”,并将输入名称参数更改为“q”。

    【讨论】:

      【解决方案2】:

      使用:

      <form method="get" action="search.php">
          <input type="text" id="txtSearch" name="q" class="searchInput" value="" />
          <input type="submit" id="btnSubmit" name="btnSubmit" value="Search" />
      </form>
      

      【讨论】:

        【解决方案3】:
        <form method="post" action="search.php?q=txtSearch">
            <input type="text" id="txtSearch" name="txtSearch" class="searchInput" value="" />
            <input type="submit" id="btnSubmit" name="btnSubmit" value="Search" />
        </form>
        

        通过这种方式提交表单,您将被重定向到search.php?q=txtSearch,并且您可以从 php 获取 $_POST 变量

        $_POST['txtSearch'] $_POST['btnSubmit']

        【讨论】:

          【解决方案4】:

          只需使用 GET 而不是 POST

          <form method="get" action="search.php">
          

          字段的名称将是查询字符串变量的名称。像这样:

          ?input_name=input_value
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-11-04
            • 1970-01-01
            • 1970-01-01
            • 2012-05-12
            • 2014-06-29
            相关资源
            最近更新 更多