Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when submit button is clicked

Tags:

html

get

What happens when submit button is clicked? Let I've a form which located on an http://example.com/ URL with the two input elements like this:

<form method="get">
    <input type="text" id="field1" name="namefield1"/>
    <input type="text" id="field2" name="namefield2"/>
    <input type="submit" value="submit"/>
</form>

What actually get request will be sent to an http-server in my specific case?

like image 732
St.Antario Avatar asked Feb 16 '14 16:02

St.Antario


People also ask

What occurs when a user clicks the submit button on a web form?

What occurs when a user clicks the Submit button on a Web form? The data from all fields in the form is sent to be processed by the action specified in the <form> tag.

What will be the output when the form submit button is clicked?

The submit value of input displays a Submit button on a form. Clicking this button will submit the form data. If you want to use an image in place of a Submit button, use the image input type.

When user clicks the submit button is known as?

The submit event fires when the user clicks a submit button ( <button> or <input type="submit">) or presses Enter while editing a field (e.g. <input type="text">) in a form. The event is not sent to the form when calling the form. submit() method directly.

What happens after submitting form?

When a normal form submits, the page is reloaded with the response from the endpoint that the form submitted to. Everything about the current page that does not exist in a persistent medium (such as cookies, or Storage) is destroyed, and replaced with the new page.


2 Answers

The form will be submitted to the server and the browser will redirect away to the current address of the browser and append as query string parameters the values of the input fields.

In terms of the HTTP protocol the following GET request HTTP request will be sent:

GET http://example.com/?namefield1=value1&namefield2=value2 HTTP/1.1
Host: example.com

Since your <form> is missing an action attribute, the browser will simply redirect to the current url by appending the values as query string parameters. So if this form was loaded from http://example.com/foo.php after submitting it, the browser will redirect to http://example.com/foo.php?namefield1=value1&namefield2=value2 where value1 and value2 will be the values enetered by the user in the corresponding input fields.

Also you might use your browser's built in debugging tools or Fiddler to inspect the exact payload that gets sent to the server.

like image 166
Darin Dimitrov Avatar answered Oct 10 '22 20:10

Darin Dimitrov


If you submit the form with a method of 'get' then it will perform a get request thus sending the data held within your input elements on the query string as a name value pair. So for example http://example.com/index.html?field1=joe&field2=bloggs

See example here if you scroll down to the Submit Button example at the bottom: http://www.w3schools.com/html/html_forms.asp

like image 42
B-Lat Avatar answered Oct 10 '22 20:10

B-Lat