Importance of Form Tag in HTML Page

Importance of form tag

  • Form Tag is Powerful - In the internet the most-used tag is form tag; without form tags the internet would be a read only repository of boring documentation. You wouldn't even be able to search for anything on the internet without a form tag. So it plays an important role in the web for sending and receiving data.

  • Before ASP.NET MVC - Before it came into the picture we had ASP.NET webforms and many developers who came directly to MVC didn't know about ASP.NET web forms. ASP.NET web forms don't expose the full power of form tags, which means you could say it's used as its own requirement.

Apart from that, as we all know, form tag is a container which contains buttons, checkboxes, and more. In Html form it enables us to enter information and submit it to the server.

But which server it going to post the data ?

The answer to the above question is the two most important attributes of form tags, and these are:

The action and the method attribute.

The action attribute tells the web browser where to send the information (or on which server to post the data). The action attribute naturally contains the URL.The URL may be absolute or relative.

For example, in the Bing search engine the code of the form tag is shown below,

  1. <form action="http://www.bing.com/search">   
  2.    <input name="s" type="text" />   
  3.    <input type="submit" value="Search!" />   
  4. </form>   
In the above code you might think that form tag does not contain any method attribute, so then how it is going to know what type of method attribute touse?
 
To understand this we need to understand some important concepts about form tag:
  • The method attribute inside form tag tells the browser whether to use Http Get or Http Post while sending data to web server. You might think that by default the method is Http Post; but that is wrong. Whatever you are doing,  whether submitting your profile image or buying something from internet, the default method used inside the form is Http Get.

  • So remember, while posting any data to server, the default method is Http get; often we confuse this question in interviews regarding what default method is used  for form tag and we think that we are posting data for form tag, so default will be post, but it doesn't work like that. You are posting data, yes it's true, but after posting does the browser get some data? The answer is "yes," so the default is "Get."

Hope this blog helped you understand about "Form tag."

Ebook Download
View all
Learn
View all