📌 Objective: Learn how to create styled forms using Bootstrap and implement built-in form validation for user input.
🔹 1. Introduction to Bootstrap Forms
Forms are essential for user input, authentication, and data submission. Bootstrap provides pre-styled form controls, labels, and validation features.
💡 Why Use Bootstrap Forms?
✔️ Pre-styled form fields that look consistent across browsers.
✔️ Built-in validation classes for error handling.
✔️ Easily customizable using Bootstrap’s grid system.
🔹 2. Bootstrap Form Basics
Forms in Bootstrap are built using the <form>
element and various input fields.
✅ Example: Basic Form
🔹 What happens?
- The form fields automatically get spacing and styling using
.form-control
.
🔹 3. Bootstrap Form Layouts
1️⃣ Inline Forms
Inline forms display inputs next to each other instead of stacking them.
✅ Example: Inline Form
🔹 What happens?
- The form fields appear in one row instead of stacking.
2️⃣ Horizontal Form Layout
Use Bootstrap’s grid system to create a horizontal form.
✅ Example: Horizontal Form
🔹 What happens?
- The label is in one column and the input field is in another.
🔹 4. Bootstrap Form Controls
1️⃣ Input Types
Bootstrap supports various input types such as text
, password
, email
, number
, date
, and file
.
✅ Example: Input Types
2️⃣ Floating Labels
Floating labels move above the input field when users type.
✅ Example: Floating Labels
🔹 What happens?
- The label floats above the input field when clicked.
3️⃣ Select Dropdowns
Use .form-select
to create a styled dropdown menu.
✅ Example: Select Dropdown
🔹 What happens?
- A styled dropdown menu appears.
4️⃣ Checkboxes & Radio Buttons
Use .form-check
for checkboxes and radio buttons.
✅ Example: Checkboxes & Radios
🔹 What happens?
- The checkbox and radio buttons are styled properly.
🔹 5. Bootstrap Form Validation
1️⃣ Client-Side Validation
Bootstrap provides built-in validation for form fields.
✅ Example: Form Validation
🔹 What happens?
- If the field is empty, an error message appears.
.invalid-feedback
shows validation messages.
2️⃣ JavaScript-Powered Validation
You can add JavaScript validation to enhance error handling.
✅ Example: JavaScript Form Validation
🔹 What happens?
- The script prevents form submission if fields are empty.
- Adds Bootstrap’s validation classes dynamically.
📝 Lesson Recap Quiz
🎯 Test your knowledge of Bootstrap forms.
📌 Multiple-Choice Questions (MCQs)
1️⃣ Which class is used for a Bootstrap-styled input field?
a) .input-field
b) .form-control
c) .form-input
d) .bootstrap-input
✅ Correct Answer: b) .form-control
2️⃣ What class is used for a Bootstrap dropdown select menu?
a) .form-dropdown
b) .form-select
c) .select-menu
d) .dropdown-control
✅ Correct Answer: b) .form-select
3️⃣ Which Bootstrap class is used for validation error messages?
a) .form-error
b) .alert-warning
c) .invalid-feedback
d) .form-danger
✅ Correct Answer: c) .invalid-feedback
📌 True or False
4️⃣ Bootstrap supports floating labels inside form fields.
✅ Answer: True
5️⃣ .form-group
is required to use Bootstrap forms.
✅ Answer: False (It is optional.)
🎯 Practical Challenge
✅ Create a Bootstrap form with:
- Floating labels
- Styled checkboxes & radio buttons
- A dropdown select field
✅ Implement Bootstrap validation with error messages.
✅ Post your solution in the discussion forum for feedback!
🎓 Lesson Summary
✅ Bootstrap forms (.form-control
) provide consistent styling for input fields.
✅ Floating labels create modern UI forms.
✅ Form validation (.invalid-feedback
) prevents incorrect user input.
✅ Bootstrap supports checkboxes, radio buttons, and dropdowns.
Leave a Reply