- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What HTML forms are and how to use them?
HTML Forms are needed to collect some data from the site visitor. For example, collecting information about a student like a name, age, address, marks, etc, while he/she is registering on the college website.
A form takes input from the site visitor and posts it to a back-end application such as CGI, ASP Script or PHP script etc. The back-end application performs required processing on the passed data based on defined business logic inside the application.
The HTML <form> tag is used to create a form in HTML.
As shown above, we have used some attributes. Here are the form attributes
HTML Form Attributes
Here are the attributes of HTML form,
Attribute & Description
ActionBackend script ready to process your passed data.
MethodMethod to be used to upload data. The most frequently used are GET and POST methods.
TargetSpecify the target window or frame where the result of the script will be displayed. It takes values like _blank, _self, _parent etc.
EnctypeYou can use the enctype attribute to specify how the browser encodes the data before it sends it to the server. Possible values are −
application/x-www-form-urlencoded − This is the standard method most forms use in simple scenarios.
mutlipart/form-data − This is used when you want to upload binary data in the form of files like image, word file etc.
HTML Form Controls
Different types of form controls are available to collect data such as text input, checkbox, radio box, file select box, submit button, etc.
Let’s see a simple example to get user input with <input> tag in an HTML form:
<!DOCTYPE html> <html> <head> <title>HTML Forms</title> </head> <body> <form> Student Name: <input type = "text" name = "sname" /><br> Student Subject: <input type = "text" name = "ssubject" /> </form> </body> </html>
With the above code, get user input for name and subject.
We have used the attributes type and name. Let’s see all other attributes for <input> tag,
Attribute & Description
typeIndicates the type of input control and for text input control it will be set to text.
nameUsed to give a name to the control which is sent to the server to be recognized and get the value
valueThis can be used to provide an initial value inside the control.
sizeAllows specifying the width of the text-input control in terms of characters
Allows specifying the maximum number of characters a user can enter into the text box.
- What are lambda expressions and how to use them in Java?
- How to use the submit button in HTML forms?
- How do we use radio buttons in HTML forms?
- How do we use checkbox buttons in HTML forms?
- What are sitemaps? How to create them?
- What are constants in Kotlin and how to create them?
- What are native methods in Java and where should we use them?
- Docker Image tags and how to use them
- What are the worst Amazon scams and how to avoid them?
- Why do we use reset button in HTML forms?
- HTML DOM forms collection
- What are MySQL stored functions and how can we create them?
- How to take user input using HTML forms?
- What are some common forms of scamming?
- What are some forms of Financing Effects?