Skip to content

Commit 580f749

Browse files
committed
started form content
1 parent 9d24388 commit 580f749

File tree

8 files changed

+602
-0
lines changed

8 files changed

+602
-0
lines changed

docs/_scripts/creating-forms.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const CreatingForms = () => {
2+
return (
3+
<div>
4+
<h1>Contact Us</h1>
5+
<form action="/submit" method="post">
6+
<label for="name">Name:</label>
7+
<input type="text" id="name" name="name" required />
8+
<br />
9+
<label for="email">Email:</label>
10+
<input type="email" id="email" name="email" required />
11+
<br />
12+
<label for="message">Message:</label>
13+
<textarea id="message" name="message" rows="4" required></textarea>
14+
<br />
15+
<button type="submit">Submit</button>
16+
</form>
17+
</div>
18+
);
19+
};
20+
21+
export default CreatingForms;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "👩🏻‍💻 Working With Forms",
3+
"position": 3,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Learn how to create forms and collect user input."
7+
}
8+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# 🙋🏻 HTML Form and Inputs
6+
7+
Forms in HTML are a fundamental way to collect user input on web pages. They enable interaction between the user and the web server, allowing users to submit data, search, and perform various tasks. This guide covers the essential concepts of forms and inputs in HTML, including form structure, attributes, and basic usage.
8+
9+
## 📋 What is an HTML Form?
10+
11+
An HTML form is defined using the `<form>` element, which acts as a container for various input controls, such as text fields, radio buttons, checkboxes, and submit buttons. The form itself can be configured to handle data submission via different methods and actions.
12+
13+
```html title="basic-form.html"
14+
<form action="/submit-form" method="post">
15+
<label for="username">Username: </label>
16+
<input type="text" id="username" name="username" required>
17+
<input type="submit" value="Submit">
18+
</form>
19+
```
20+
21+
### Explanation:
22+
- **`<form>`**: The main element that contains form controls.
23+
- **`action` attribute**: Specifies the URL where form data will be sent.
24+
- **`method` attribute**: Specifies the HTTP method (`get` or `post`).
25+
26+
## 🔘 Common Form Elements
27+
28+
### 1. Input Fields
29+
The `<input>` element is one of the most versatile elements in HTML forms. It can be used for various types of input, specified by the `type` attribute.
30+
31+
```html title="input-elements.html"
32+
<form>
33+
<label for="email">Email:</label>
34+
<input type="email" id="email" name="email" required>
35+
36+
<label for="password">Password:</label>
37+
<input type="password" id="password" name="password" required>
38+
39+
<label for="age">Age:</label>
40+
<input type="number" id="age" name="age" min="0" max="120">
41+
42+
<input type="submit" value="Register">
43+
</form>
44+
```
45+
46+
### 2. Textarea
47+
The `<textarea>` element is used for multi-line text input.
48+
49+
```html title="textarea-example.html"
50+
<form>
51+
<label for="comments">Comments:</label>
52+
<textarea id="comments" name="comments" rows="4" cols="50"></textarea>
53+
<input type="submit" value="Submit">
54+
</form>
55+
```
56+
57+
### 3. Select (Dropdown)
58+
The `<select>` element creates a dropdown list for users to choose from predefined options.
59+
60+
```html title="select-example.html"
61+
<form>
62+
<label for="options">Choose an option:</label>
63+
<select id="options" name="options">
64+
<option value="option1">Option 1</option>
65+
<option value="option2">Option 2</option>
66+
<option value="option3">Option 3</option>
67+
</select>
68+
<input type="submit" value="Submit">
69+
</form>
70+
```
71+
72+
### 4. Buttons
73+
Buttons can be defined using the `<button>` or `<input type="button">` elements.
74+
75+
```html title="button-example.html"
76+
<form>
77+
<button type="submit">Submit</button>
78+
<button type="reset">Reset</button>
79+
</form>
80+
```
81+
82+
## ✏️ Attributes of Input Elements
83+
84+
### Commonly Used Attributes:
85+
- **`required`**: Ensures that the field must be filled before submission.
86+
- **`placeholder`**: Provides a hint to the user about what to enter.
87+
- **`value`**: Specifies the default value.
88+
- **`disabled`**: Disables the input, making it uneditable.
89+
- **`readonly`**: Makes the input read-only.
90+
91+
```html title="input-attributes.html"
92+
<input type="text" placeholder="Enter your name" required>
93+
<input type="email" placeholder="Enter your email" value="example@example.com" readonly>
94+
```
95+
96+
## 🌐 Form Submission
97+
98+
The `method` attribute of the `<form>` tag can be set to:
99+
- **`get`**: Appends the form data to the URL. Typically used for non-sensitive data.
100+
- **`post`**: Sends data as a request body. Preferred for sensitive or large amounts of data.
101+
102+
### Example:
103+
```html title="form-methods.html"
104+
<form action="/search" method="get">
105+
<label for="query">Search:</label>
106+
<input type="text" id="query" name="query">
107+
<input type="submit" value="Search">
108+
</form>
109+
110+
<form action="/submit-form" method="post">
111+
<label for="feedback">Feedback:</label>
112+
<textarea id="feedback" name="feedback"></textarea>
113+
<input type="submit" value="Submit">
114+
</form>
115+
```
116+
117+
## ✅ Form Best Practices
118+
- **Use labels** to associate text descriptions with input elements for accessibility.
119+
- **Group related fields** using the `<fieldset>` and `<legend>` tags.
120+
- **Provide feedback** to users for better form interaction.
121+
- **Validate inputs** both on the client-side using HTML attributes and JavaScript, and on the server-side for security.
122+
123+
```html title="fieldset-example.html"
124+
<form>
125+
<fieldset>
126+
<legend>Personal Information</legend>
127+
<label for="firstname">First Name:</label>
128+
<input type="text" id="firstname" name="firstname" required>
129+
130+
<label for="lastname">Last Name:</label>
131+
<input type="text" id="lastname" name="lastname" required>
132+
</fieldset>
133+
134+
<input type="submit" value="Submit">
135+
</form>
136+
```
137+
138+
By following these guidelines, you can create well-structured and user-friendly forms that improve the user experience and ensure reliable data collection.
139+
140+
## 🚀 Summary
141+
142+
This guide covered the basics of HTML forms and input elements, including form structure, common input types, attributes, and best practices. By understanding these concepts, you can create interactive web forms that enhance user engagement and data collection on your website.
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# 🙋🏻 HTML Form elements
6+
7+
Forms in HTML consist of various elements that help gather user input efficiently. This guide covers the most commonly used form elements, explaining their attributes, usage, and examples to help you build user-friendly web forms.
8+
9+
## 🔤 Text Input Elements
10+
11+
### Single-line Text Input
12+
The `<input type="text">` element is used for basic, single-line text fields.
13+
14+
```html title="text-input.html"
15+
<form>
16+
<label for="username">Username:</label>
17+
<input type="text" id="username" name="username" placeholder="Enter your username" required>
18+
</form>
19+
```
20+
21+
### Password Input
22+
The `<input type="password">` element masks user input, ideal for password fields.
23+
24+
```html title="password-input.html"
25+
<form>
26+
<label for="password">Password:</label>
27+
<input type="password" id="password" name="password" required>
28+
</form>
29+
```
30+
31+
### Email Input
32+
The `<input type="email">` element ensures that the input matches the standard email format.
33+
34+
```html title="email-input.html"
35+
<form>
36+
<label for="email">Email:</label>
37+
<input type="email" id="email" name="email" placeholder="example@example.com" required>
38+
</form>
39+
```
40+
41+
### Number Input
42+
The `<input type="number">` element is for numeric input and can include attributes like `min`, `max`, and `step`.
43+
44+
```html title="number-input.html"
45+
<form>
46+
<label for="age">Age:</label>
47+
<input type="number" id="age" name="age" min="1" max="120">
48+
</form>
49+
```
50+
51+
## 📝 Multi-line Text Input
52+
The `<textarea>` element allows users to input multiple lines of text.
53+
54+
```html title="textarea-example.html"
55+
<form>
56+
<label for="comments">Comments:</label>
57+
<textarea id="comments" name="comments" rows="4" cols="50" placeholder="Enter your comments here..."></textarea>
58+
</form>
59+
```
60+
61+
## 🔘 Radio Buttons and Checkboxes
62+
63+
### Radio Buttons
64+
Radio buttons are used when only one option from a set is needed.
65+
66+
```html title="radio-buttons.html"
67+
<form>
68+
<p>Choose your favorite color:</p>
69+
<input type="radio" id="red" name="color" value="red">
70+
<label for="red">Red</label><br>
71+
72+
<input type="radio" id="blue" name="color" value="blue">
73+
<label for="blue">Blue</label><br>
74+
75+
<input type="radio" id="green" name="color" value="green">
76+
<label for="green">Green</label>
77+
</form>
78+
```
79+
80+
### Checkboxes
81+
Checkboxes allow users to select multiple options.
82+
83+
```html title="checkboxes.html"
84+
<form>
85+
<p>Select your hobbies:</p>
86+
<input type="checkbox" id="sports" name="hobby" value="sports">
87+
<label for="sports">Sports</label><br>
88+
89+
<input type="checkbox" id="reading" name="hobby" value="reading">
90+
<label for="reading">Reading</label><br>
91+
92+
<input type="checkbox" id="music" name="hobby" value="music">
93+
<label for="music">Music</label>
94+
</form>
95+
```
96+
97+
## 🔽 Dropdown Lists
98+
The `<select>` element is used to create a dropdown list.
99+
100+
```html title="dropdown-example.html"
101+
<form>
102+
<label for="country">Choose your country:</label>
103+
<select id="country" name="country">
104+
<option value="usa">United States</option>
105+
<option value="canada">Canada</option>
106+
<option value="uk">United Kingdom</option>
107+
</select>
108+
</form>
109+
```
110+
111+
## 📅 Date and Time Inputs
112+
113+
### Date Input
114+
The `<input type="date">` element lets users pick a date from a calendar.
115+
116+
```html title="date-input.html"
117+
<form>
118+
<label for="dob">Date of Birth:</label>
119+
<input type="date" id="dob" name="dob">
120+
</form>
121+
```
122+
123+
### Time Input
124+
The `<input type="time">` element is for selecting time.
125+
126+
```html title="time-input.html"
127+
<form>
128+
<label for="appt">Select a time:</label>
129+
<input type="time" id="appt" name="appt">
130+
</form>
131+
```
132+
133+
## 🖱 Buttons
134+
Buttons can be created using the `<button>` element or `<input>` with `type="button"`, `submit`, or `reset`.
135+
136+
```html title="buttons-example.html"
137+
<form>
138+
<button type="submit">Submit</button>
139+
<button type="reset">Reset</button>
140+
</form>
141+
```
142+
143+
## 📝 Summary
144+
HTML provides a wide range of elements to create forms, each suited for different types of user input. Understanding how to use these elements effectively helps in building interactive and accessible forms.

docs/working-with-forms/form-handlers.mdx

Whitespace-only changes.

docs/working-with-forms/form-validation.mdx

Whitespace-only changes.

docs/working-with-forms/input-attributes.mdx

Whitespace-only changes.

0 commit comments

Comments
 (0)