Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if the action field in a <form> has parameters?

Is there a well-supported, common behavior that I can expect if I do something like this in HTML:

<form method="get" action="/somePage.html?param1=foo&param2=foo">   <input name="param2"></input>   <input name="param3"></input> </form> 

Seems like this sort of thing is inherently ridiculous, but I've seen it used here and there and I was wondering what on Earth the expected behavior should be. Are browsers smart enough to tack on "&param2=whatever&param3=whatever" to the action, or do they just throw in a second question mark? Or what? Are there cases where this is actually the right way to do things?

like image 276
Brandon Yarbrough Avatar asked Apr 09 '09 00:04

Brandon Yarbrough


People also ask

What does the action attribute on a form element do?

The action attribute defines the action to be performed when the form is submitted. Usually, the form data is sent to a file on the server when the user clicks on the submit button.

What should I put in a form action attribute?

The HTML | action Attribute is used to specify where the formdata is to be sent to the server after submission of the form. It can be used in the <form> element. Attribute Values: URL: It is used to specify the URL of the document where the data to be sent after the submission of the form.

What does action attribute takes as a value?

The HTML form action attribute defines what should happen to data when a form is submitted on a web page. The value of the action attribute should be the URL of the web resource that will process the contents of the form.

Does form need action attribute?

Yes, the form is required to have an action attribute in HTML4. If it's not set, the browser will likely use the same method as providing an empty string to it. You really should set action="" which is perfectly valid HTML4, follows standards, and achieves the same exact result.


1 Answers

If the method attribute is set to GET, the browser drops the querystring parameters from the action attribute before constructing the form argument values.

So in your example, the request to the server on submit will look like: /somePage.html?param2=value&param3=value

So no, when the method is "GET", as in your example, there's no reason to do this.

like image 165
Rex M Avatar answered Sep 27 '22 19:09

Rex M