开发者

can a forms action url contain querystring values? [duplicate]

This question already has answers here: What happens if the action field in a <form> has parameters? (4 answers) 开发者_如何学编程 Closed 2 years ago.

can a forms action url contain querystring values?


Yes

it can.

But

when method="get" then the querystring will be stripped out and replaced by the form input names/values (since the form controls are those that build the GET querystring).

<form method="get" action="?param=foo">
    <input type="hidden" name="param" value="bar" />
</form>

will submit param=bar

To keep the value you should specify method="post" on the form.

<form method="post" action="?param=foo">
    <input type="hidden" name="otherparam" value="bar" />
</form>

will submit param=foo&otherparam=bar

<form method="post" action="?param=foo">
    <input type="hidden" name="param" value="bar" />
</form>

will submit param=foo&param=bar (so, depending on how you process the request, you could get either an array value or unexpected results).


Yes, it can.

(Keystrokes)


I've just checked using a reduced test case:

  • Form.htm that contains a form with an action of default.aspx?query=1 and a submit button.
  • default.aspx that contains code in Page_Load to write out Request.QueryString["query"]

The result I got when clicking on the button was a page that read:

1

So, the answer is yes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜