在action属性中已包含?key = val查询字符串的表单提交将忽略该查询字符串 [英] Form submission with a ?key=val query string already in the action attribute ignores that query string

查看:75
本文介绍了在action属性中已包含?key = val查询字符串的表单提交将忽略该查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试在向页面本身提交页面的同时保留页面的当前查询字符串.

So I'm trying to submit a page to itself while retaining the current query string of the page.

因此页面为sb.local/sb/cat.php?brandcode=JM&t=cat_items,我提取了查询字符串并将其重新粘贴到html表单中以保留参数.这是结果形式:

So the page is sb.local/sb/cat.php?brandcode=JM&t=cat_items I pull off the query string and stick it back into the html form to preserve the parameters. This is the resulting form:

<form id="brand-select" method="get" action="?brandcode=JM&t=cat_items" name="brand-select">
Brand:
<select id="brandcode" style="width:207px" tabindex="3" name="brandcode" required="">
<option value=""></option>
<option class="brand-option" value="AX" data-brandid="110"> Aetrex </option>
<option class="brand-option" value="AL" data-brandid="12"> Alden </option>
<option class="brand-option" value="ETC" data-brandid="11"> Etc </option>
</select>
<input type="submit" value="go">
</form>

但是,当我通过选择Aetrex(值AX)的下拉列表提交表单时,它的网址为:

When I submit the form by choosing the dropdown for Aetrex (value AX), however, it goes to a url of:

sb.local/sb/cat.php?brandcode=AX 换句话说,它删除了动作中的"t = cat_items".它还删除了"brandcode = JM",但由于它们是重复的,因此我几乎可以期待.

sb.local/sb/cat.php?brandcode=AX in other words, it cuts out the "t=cat_items" that is in the action. It also cuts out the "brandcode=JM" but I would almost expect that since they're duplicates.

这不是我所期望的,我希望如果action属性中有一个查询字符串,它将在该查询字符串后附加表单值(例如sb.local/sb/cat.php?brandcode=JM&t=cat_items&brandcode=AX.相反,它似乎只用了全部替换查询字符串)表单中的那些元素.

That's not what I expected, I expected that if there is a query string in the action attribute, it would append form values to that query string (e.g. sb.local/sb/cat.php?brandcode=JM&t=cat_items&brandcode=AX. Instead it seems to be replacing the query string entirely with only those elements that are in the form.

表单操作属性是否不能用于存储查询参数,而只能用于存储更多基本的url信息?

Is the form action attribute not usable for storing query parameters, only more basic url info?

请注意,我可以通过解析每个参数,然后将每个参数手动放入其自己的隐藏字段中来解决此问题,除了我想允许更改的任何参数外,我只是希望有一种更简单的方法.
我使用无冲突的查询字符串进行了测试,即使在没有冲突的情况下(在Firefox中),该字符串也已全部替换,因此基于该查询字符串似乎在get form的action属性中毫无用处?还是我错过了一些东西.

Note that I can work around this by parsing every parameter and then putting each parameter into its own hidden field manually, except for any parameters that I want to allow to change, I was just hoping that there was some kind of simpler way.
I tested with a non-conflicting query string and that was replaced in whole even when there wasn't a conflict (in Firefox), so based on that it seems that query strings are useless in the action attribute of get forms? Or am I missing something.

推荐答案

我知道这是一个老问题,但是解决方案实际上非常简单(整洁!).

I know this is an old question, but the solution is actually pretty simple (and neat!).

您要做的就是发送带有name="key"value="value"格式的带有隐藏输入字段的查询字符串.

All you have to do is sending the querystring with hidden input fields in the format name="key" and value="value".

?brandcode = JM& t = cat_items会翻译"为:

?brandcode=JM&t=cat_items would "translate" into:

<input type="hidden" name="brandcode" value="JM" />
<input type="hidden" name="t" value="cat_items" />

从您的action中完全删除查询字符串.

Completely remove the querystring from your action.

这篇关于在action属性中已包含?key = val查询字符串的表单提交将忽略该查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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