All about HTML5 for Absolute Beginners: Part 5
Hello everyone! Welcome back to the blog, and I hope you're making great progress in learning HTML5 with me.
In this blog, we’ll dive into HTML5 forms, covering essential tags like <form>, <input>, <textarea>, and <select>, and explain how they work together to collect user input effectively.
HTML5 Forms: A Beginner's Guide to Creating User-Friendly Web Forms
In the last episode, we had a look at the input and label. These are widely used in making HTML forms on websites.
If you wish to submit some information to apply for something, such as an application, complaint ticket, inquiry, or whatever, websites have forms to collect your necessary information to stay in touch with you and record your concerns. So, we will also need to implement a form on our website and start learning the foundation with HTML.
Now, a form is a thing that requires both a front-end and a back-end.
On the front end, the user will fill in their information, which will securely be sent to the back-end, where it will be accessible by the website owners. In HTML5, we can build the front end of the form, but for the back-end, we will need help from different technologies such as PHP, JavaScript, or others. We will cover that later in the series, but today, let's focus on the front end.
The method attribute decides which HTTP method the data will be sent through because it will be sent via an HTTP request.
Understanding HTTP and HTTPS
Common HTTP Methods Explained
GET Method
POST Method
Similarly, if you want to store some data in your database or send data to another source, then use the POST method.
PUT Method
PATCH Method
DELETE Method
Essential HTML5 Form Elements
The form tag
<form action="index.php" method="POST">
<!-- Form elements go here -->
</form>
When you write a form tag like the one in the example, nothing would appear on the screen. This is because the form tag tells html that a form is going to be written in these tags, and the data for the backend should head over to the file in the action attribute, in this case, a PHP file index.php.
In between these form tags, you will write your label tags and input tags. You can place images, anchor tags for any links, if you wish to give, an input with a type equals file if you wish for the user to submit an image or something and much much more.
But how will the form be submitted? With a button of course.
Button tag
<button>click me</button>
To create a simple button, we use the button tag. Just a simple tag, you can try it out on your own.
In forms, usually, we use the input tag with a type equal to submit. This is great for forms where you have to submit a particular data. For example,
<input type="submit" />
Textarea tag
<textarea rows="4"></textarea>
If you want the user to fill in a big message consisting of multiple lines, then use the textarea tag. Rows attribute determines the number of visible text lines. It will create a rectangular box for a nice and big input. Try it out!
Select and Option
Wrapping Up
I aim to make my blogs into small digestible chunks of information and do not intend to make my audience feel that coding or web development is very complex or impossible. So that is why I'm ending this blog here. Please let me know about this idea and what length you would prefer for my upcoming blogs.
Thank you so much for spending time with me and if you have questions about HTML5 forms then drop them in the comments below, and I’ll be happy to answer!"