Skip to content

01. Using Forms

HTML forms are essential for collecting user input, submitting data, and creating interactive web experiences. The <form> element, along with various input types and form controls, enables users to enter data that can be processed by servers. Understanding forms is crucial for building functional web applications.

<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<button type="submit">Submit</button>
</form>

Submission URL:

<form action="/api/submit" method="post">
<!-- Form fields -->
</form>

HTTP method:

<form action="/submit" method="post">
<!-- POST request -->
</form>
<form action="/search" method="get">
<!-- GET request -->
</form>

Encoding type:

<form action="/upload" method="post" enctype="multipart/form-data">
<!-- File upload -->
</form>
<input type="text" name="username" placeholder="Username">
<input type="email" name="email" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<textarea name="message" rows="4" cols="50" placeholder="Your message"></textarea>
<select name="country">
<option value="us">United States</option>
<option value="uk">United Kingdom</option>
</select>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
<button type="button">Click Me</button>
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<input type="email" name="email" required>