HTML Tutorials

The method attribute

The method attribute specifies which HTTP method will be used to send the form data to the server. The allowed values are get and post, which correspond to the HTTP GET and POST methods. The default used when you don’t apply the method attribute is get, which is unfortunate because most forms require HTTP POST. You can see that we have specified the post value for the form in the example, as follows:

<form method="post" action="http://titan:8080/form">

GET requests are for safe interactions, which means you can make the same request as many times as you want and there will be no side effects. POST requests are for unsafe interactions, where the act of submitting the data changes some kind of state. This is most commonly the case when dealing with web applications. These conventions are set by the World Wide Web Consortium (W3C). The rule of thumb is that GET requests should be used for all read-only information retrieval, while POST requests should be used for any operation that changes the application state. It is important to use the right kind of requests. If you are unsure, err on the side of caution and use the POST method.