使用查询字符串参数提交GET表单并隐藏参数消失 [英] submitting a GET form with query string params and hidden params disappear

查看:160
本文介绍了使用查询字符串参数提交GET表单并隐藏参数消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下形式:

 < form action =http://www.blabla.com?a=1& ; b = 2method =GET> 
< input type =hiddenname =cvalue =3/>
< / form>

提交此表单(GET表单)时,参数a和b正在消失。
是否有这个原因?
是否有避免这种行为的方法?

解决方案

是不是隐藏参数用于开始...?

 < form action =http://www.example.commethod =GET> ; 
< input type =hiddenname =avalue =1/>
< input type =hiddenname =bvalue =2/>
< input type =hiddenname =cvalue =3/>
< input type =submit/>
< / form>

我不会指望任何浏览器保留动作网址中的任何现有查询字符串。



根据规格( RFC1866 ,page 46; HTML 4.x 第17.13节。 3)状态:

lockquote

如果方法是get并且操作是HTTP URI,则用户代理将采取action的值,附加'?',然后附加表单数据集,使用application / x-www-form-urlencoded内容类型编码。

也许人们可以对action-URL进行百分比编码,以嵌入问号和参数,然后跨越手指,希望所有浏览器都会保留该URL(并验证服务器是否理解它)。但我永远不会依赖它。



顺便说一句:对于非隐藏的表单字段,这并不是不同的。对于POST,动作URL可以包含查询字符串。


Consider this form:

<form action="http://www.blabla.com?a=1&b=2" method="GET">
    <input type="hidden" name="c" value="3" /> 
</form>

When submitting this form (a GET form) the parameters a and b are disappearing. Is there a reason for that? Is there a way of avoiding this behaviour?

解决方案

Isn't that what hidden parameters are for to start with...?

<form action="http://www.example.com" method="GET">
  <input type="hidden" name="a" value="1" /> 
  <input type="hidden" name="b" value="2" /> 
  <input type="hidden" name="c" value="3" /> 
  <input type="submit" /> 
</form>

I wouldn't count on any browser retaining any existing query string in the action URL.

As the specifications (RFC1866, page 46; HTML 4.x section 17.13.3) state:

If the method is "get" and the action is an HTTP URI, the user agent takes the value of action, appends a `?' to it, then appends the form data set, encoded using the "application/x-www-form-urlencoded" content type.

Maybe one could percent-encode the action-URL to embed the question mark and the parameters, and then cross one's fingers to hope all browsers would leave that URL as it (and validate that the server understands it too). But I'd never rely on that.

By the way: it's not different for non-hidden form fields. For POST the action URL could hold a query string though.

这篇关于使用查询字符串参数提交GET表单并隐藏参数消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆