2

can a forms action url contain querystring values?

Blankman
  • 248,432
  • 309
  • 736
  • 1,161

3 Answers3

2

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).

Kamafeather
  • 7,050
  • 13
  • 52
  • 88
1

Yes, it can.

(Keystrokes)

Matti Virkkunen
  • 61,328
  • 9
  • 119
  • 152
  • @Kiquenet: It's a "can you do X" question, it hardly needs any sample code. I'll rather vote to close this as a dupe of a better question that has more discussion about it. – Matti Virkkunen Jan 26 '17 at 12:59
0

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.

Rob
  • 44,468
  • 23
  • 118
  • 147