Creating Forms in HTML

A form contains elements that will be submitted to a url defined. Example of forms are login form, registration form and contact us form. All elements that will be send should be inside the <form> tag. The url where the form will be submitted is define inside the action attribute. The form also have different methods to send the data. The common methods use are Get and Post method. The Get method will append the parameters(value) to the url of the web page and will be visible to the user. The post method will hide the value of parameters to the user, thus more secured.

Get Method

For example,

<form 
   action="https://javapointers.com/html/creating-forms-in-html/"
   method="GET"
>
   Username: <input type="text" name="username" /><br />
   Password: <input type="password" name="password"><br />
   <input type="submit" value="Submit" />
</form>
Output
Username:
Password:

If you will notice in the url, there will be additional text that is appended:
https://javapointers.com/html/creating-forms-in-html/?username=javapointers&password=javapointers

Therefore making it a security risk.

Post Method

<form 
   action="https://javapointers.com/uncategorized/creating-forms-in-html/"
   method="POST"
>
   Username: <input type="text" name="username" /><br />
   Password: <input type="password" name="password"><br />
   <input type="submit" value="Submit" />
</form>
Output
Username:
Password:

This method will not display the parameters in the url and more secured than GET. The parameters are send using post data.

Post is more secured than Get but there are times that its more convenient to use get if you need to display the query to the user. For example, Google uses Get method in their search query so that user can check what they are searching and can edit the search query directly to the url.

Share this tutorial!