get请求表单的action属性后不能带参数

最近在编写网页程序时,有类似如下代码:

 <form action="index.php?controller=message&method=search" method="get">
                <input name="keywords" type="text" class="text" id="input" style="height:40px;" placeholder="请输入您要搜索的标题...">
                <input name="" type="submit" class="btn" value="搜索">
            </form>
不过我发现在后台获取参数时,一直获取不到表单action中的 method参数值controller=message&method=search

后经查询发现,浏览器会将表单数据封装为字符串,如controller=message&method=search,然后直接附在表单的 action URL 之后。这两者之间用问号(?)进行分隔。如果GET请求的表单action属性中已经包含参数,浏览器会直接将其过滤掉,再附加form表单数据

因此,GET请求方式的表单的action属性中不能附带任何参数,如果需要附加额外的参数,可以采用如下方式:

  1. 采用POST请求方式,在form中增加属性method="post"即可。
  2. 如果仍然想使用GET请求方式,可以在form表单中添加相应的隐藏文本域,例如:
  1. <form action="index.php?controller=message&method=search" method="get">
                <input type="hidden" name="controller" value="message"> 
                <input type="hidden" name="method" value="search"> 
                    <input name="keywords" type="text" class="text" id="input" style="height:40px;" placeholder="请输入您要搜索的标题...">
                    <input name="" type="submit" class="btn" value="搜索">
                </form>

原文地址:http://www.365mini.com/page/get-method-form-conflict-with-action-which-has-parameter.htm
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值