【问题标题】:PHP form not sending GET [duplicate]PHP表单不发送GET [重复]
【发布时间】:2016-01-14 18:13:45
【问题描述】:

所以我正在为我的 webwshop 开发一个搜索功能,而且我已经走了很远。我已经使用 search.php 文件中的 SELECT 代码设置了 GET 函数。所以我“非常自信”地认为让我们快速完成表格,我就完成了......

事实证明,这并不容易。我现在有这个代码,我似乎无法用 get 发送数据。现在,当您搜索某些内容时,您得到的只是http://buitenlandseproducten.nl/search.php?id=,但没有任何内容存储在 id 中。

  <div class="form-group">
    <span class="col-md-1 col-md-offset-1 text-center"><i class="fa fa-envelope-o bigicon"></i></span>
    <div class="col-md-8">
      <input id="form" name="form" type="text" placeholder="Search" class="form-control" >
    </div>
    <div class="col-md-12 text-center">
      <?php
        echo '<p>'. '<a href="search.php?id='.$_POST['form'].'">' . '<button type="submit" class="btn btn-secondary">' . 'Search' . '</button>' . '</a>' . '<br />';
      ?>
    </div>
  </div>

如果有人能在这里帮助我,你将永远是我的英雄! 非常感谢您的帮助!

【问题讨论】:

  • 您没有表单标签。你有一个文本元素。
  • 这是从哪里来的? $_POST['form']这里没有足够的代码,你没有检查错误。

标签: php forms get


【解决方案1】:

你混合了 GET 和 POST:

<form action="/search.php" method="get">
    <div class="form-group">
         <span class="col-md-1 col-md-offset-1 text-center"><i class="fa fa-envelope-o bigicon"></i></span>
         <div class="col-md-8">
             <input id="form" name="form" type="text" placeholder="Search" class="form-control" >
         </div>
         <div class="col-md-12 text-center">


<?php
    // check if the parameter is set.
    if (isset($_GET['form'])) {
        echo '<p><a href="search.php?id='.urlencode($_GET['form']).'"><button type="submit" class="btn btn-secondary">Search</button></a><br />';
    }
  ?>

        </div>
    </div>
</form>

【讨论】:

  • 是的,我有点搞砸了......我可能需要睡觉或者我什至忘记了表单标签>。
【解决方案2】:
<form method="GET" action="search.php">
<input id="form" name="id" type="text" placeholder="Search" class="form-control" />
<input type='Submit' Value="Search!"/>
</form>

这应该给你我想要的。

<div class="form-group">
    <span class="col-md-1 col-md-offset-1 text-center"><i class="fa fa-envelope-o bigicon"></i></span>
    <div class="col-md-8">
         <form method="GET" action="search.php">
<input id="form" name="id" type="text" placeholder="Search" class="form-control" />
<input type='Submit' Value="Search!"/>
</form>
    </div>
    <div class="col-md-12 text-center">
      <?php
       // I don't know why you have this echo below here, its not necessary for what you're trying 
// echo '<p>'. '<a href="search.php?id='.$_POST['form'].'">' . '<button type="submit" class="btn btn-secondary">' . 'Search' . '</button>' . '</a>' . '<br />';
      ?>
    </div>
  </div>

链接到 search.php 并创建一个 get 字段并从 POST 字段为其分配值的 href 元素有点拉伸它,而不是真正聪明的做法。 祝你好运,你需要它:)

【讨论】:

【解决方案3】:

您的 $_POST['form'] 似乎没有设置。像这样使用 $_POST 意味着您在使用表单进入另一个页面后访问表单。这正常吗?感觉不太正常。尤其是当它没有使用 strip_tags 或 htmlentities 保护时。 如果您需要帮助,则需要显示其他表单页面的代码,因为这就是问题所在。

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data#The_POST_method

【讨论】:

  • 是的,我完全忘记设置表单了......我知道如何以及为什么但我做到了......谢谢你的链接!
【解决方案4】:

试试这个:

<form action="/search.php" method="GET">
  <div class="form-group">
    <span class="col-md-1 col-md-offset-1 text-center"><i class="fa fa-envelope-o bigicon"></i></span>
    <div class="col-md-8">
      <input id="form" name="id" type="text" placeholder="Search" class="form-control" >
    </div>
    <div class="col-md-12 text-center">
      <?php
        echo '<p>'. '<a href="search.php?id='.$GET['id'].'">' . '<button type="submit" class="btn btn-secondary">' . 'Search' . '</button>' . '</a>' . '<br />';
      ?>
    </div>
  </div>
</form>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 1970-01-01
    相关资源
    最近更新 更多