Need for Forms

Forms provide a way for data to be collected from the user. Usually, the collected data is sent to the server for processing. There are some situations where the data is processed within the web page using JavaScript. HTML is used for providing the structure for forms. CSS is used for styling the forms to make them more pleasing. JavaScript is used for validating the data before sending it to servers for processing. A server-side language such as PHP or Python can be used for processing the data.

Form element

The form element is used for declaring a section of the web page as a form. It contains other form-related elements. Usually the form element is accompanied by the action attribute. We can use the action attribute for specifying the web page that will handle the form. If the action attribute is omitted then the data is processed within the same web page as the form. Another commonly used attribute is the method attribute. This attribute is used for specifying the method used for transmitting the data entered in the form. The two methods are GET and POST.

<form action="example.php" method="post">


The form element also supports a target attribute just like a link. The value of the attribute determines the location where the next page will be opened.

GET method

The GET method is the default method used for transmission of form data. In this method, the form data is appended to the end of the URL. This makes the form data visible to everyone who uses the URL. This can be useful for reference links. Since the data is attached to the URL, we can have pages with already filled forms. The most common use case for this method is search results. Since most search results send data by getting method, it is easy to construct a URL with a specific search term already inserted. These URLs can be bookmarked for easy access. However, due to the transparent nature of the GET method, it is not useful for sending sensitive data like passwords.

POST method

The post method is a secure alternative for GET method. The data is not attached to the end of the URL like in the GET method. This means that the form data cannot be filled beforehand. This method is more suitable for sensitive information like passwords that need to be sent securely over the browser. Another advantage to post method is that it can be used to send large amounts of data. The GET method works only with 3000 characters or less.

Use GET method if you want to have a shareable URL containing nonsensitive results. Use the POST method for sending sensitive data like personal information.