douyu4535 2013-11-18 15:08
浏览 29
已采纳

表单输入传递参数到错误的URL

I'm trying to make my form pass a parameter to a link like this :

index.php?action=2&parameter=value

Instead, all it does is pass the parameter like this:

index.php?parameter=value

This is my code :

<form class="navbar-form navbar-left" action="index.php?action=2" method="get" name="search">
  <div class="form-group">
      <input type="text" class="form-control" placeholder="put something here...." name="search" width="100">
  </div>
  <button type="submit" class="btn btn-default">search</button>
</form>

The form is located in my index.php?action=2 template but is passing the parameter back to the original index.php file instead of index.php?action=2 file.

I want to use the parameter later as a $_GET with few more parameters in order to search and sort the data taken from DB. The DB php code I wrote works fine, and when I create the link myself it all works nice, but not in the scenario when I try to type the search value in the textbox.

How do I avoid that ?

Thanks in advance!

Edit :

I have a switch in my index.php file which does :

    case 2:
    include "_template/__test.php";
    break;

My form is located in the above __test.php file.

  • 写回答

1条回答 默认 最新

  • dongqiang2024 2013-11-18 15:14
    关注

    What you're trying to do can be accomplished by using a hidden field. Add the following input field in your form:

    <input type="hidden" name="action" value="<?php echo $_GET['action']; ?>" />
    

    So, when you pass the action parameter, it will generate an input field with the sent value ($_GET['action']) and will be passed to the PHP script when the form is submitted.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条