hashnode-blogs

Forms and Input Elements in HTML πŸ“„

In real life, forms are used to take information from the user/person. For example forms for job applications and entrance examinations.

This is what form on a paper looks like:

Here, you will notice blanks that need to be filled with appropriate information.

So, for these blanks, there are input elements in HTML.

<input />

input tag is an inline-level tag.

Here is how a form in HTML looks like

Various Input elements - Explained βš™οΈ

Information can be of various types. For example text, number, email address, password, date, time, etc.

Elements/tags for Options

Complete code - for a form πŸ’»

We need to wrap all the input elements inside <form> </form> tag like this

<form>
    <label for="name">Name:</label>
    <input 
        type="text" 
        id="name" 
        name="name" 
        placeholder="Enter your name" 
        required
    >
    <br>

    <label for="email">Email:</label>
    <input 
        type="email" 
        id="email" 
        name="email" 
        placeholder="Enter your email" 
        required
    >
    <br>

    <label for="password">Password:</label>
    <input 
        type="password"     
        id="password" 
        name="password"     
        placeholder="Enter your password" 
        required
    >
    <br>
    
    <input type="submit" value="Submit">
    <input type="reset" value="Reset">
</form>

The preview:

Attributes explained:

Read more about Forms - Official Docs


Why and how we use forms - a technical dive 🏊

Form is used to take information from the user.

The steps are:

  1. Creating a form using HTML

  2. Handling the form submission (when submit button is clicked) using javascript.

  3. data is sent to the backend.

  4. In the backend, we validate the data to determine if it is correct or not,

  5. we send back errors to the frontend ( on the webpage ) if there are any

  6. if the data is all correct, we store it in the database and send a success message to the frontend

  7. and the frontend shows the user a congratulations message

🚩 We will be learning more about forms and data in JAVASCRIPT.

⚑ There are no hard and fast rules in design. Observe everything and design your own way through it.


Exercises 🏌️

Here are some free and worth practicing exercises on w3schools.


Source codes

In the next blog, I will be making a simple project using HTML5 to summarize this whole blog-series.