# Forms Concept's forms use Bootstrap 5 with custom styling for borders, focus states, and spacing. The template includes form validation patterns and Tom Select for enhanced select boxes. ## Concept Form Styling ### Custom Variables ```scss // From Concept's _variables.scss $input-border-color: #d4d9e3; $input-focus-border-color: #5969ff; $input-focus-box-shadow: 0 0 0 0.2rem rgba(#5969ff, 0.25); $font-size-base: 0.875rem; $body-color: #3d405c; ``` ### Form Elements Concept's forms use consistent spacing and styling: ```html
Basic Form Elements
We'll never share your email with anyone else.
``` ### Textarea ```html
``` ### Select ```html
``` ### Checkboxes and Radios ```html
``` ## Form Layouts ### Vertical Form ```html
``` ### Horizontal Form ```html
``` ### Inline Form ```html
``` ## Input Groups ### Basic Input Group ```html
@
.00
$ .00
``` ### With Buttons ```html
``` ## Form Validation ### HTML5 Validation ```html
Looks good!
Please provide a valid first name.
``` ### Custom Validation ```javascript // Real-time validation function validateEmail(input) { const email = input.value; const isValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); if (isValid) { input.classList.remove('is-invalid'); input.classList.add('is-valid'); } else { input.classList.remove('is-valid'); input.classList.add('is-invalid'); } } // Password strength checker function checkPasswordStrength(password) { let strength = 0; if (password.length >= 8) strength++; if (/[a-z]/.test(password)) strength++; if (/[A-Z]/.test(password)) strength++; if (/[0-9]/.test(password)) strength++; if (/[^A-Za-z0-9]/.test(password)) strength++; return { score: strength, label: ['Very Weak', 'Weak', 'Fair', 'Good', 'Strong'][strength] }; } ``` ## Advanced Form Components ### File Upload ```html
Drag & Drop files here

or

``` ### Date & Time Inputs ```html
``` ### Range Slider ```html
``` ## Form Patterns ### Login Form ```html
Please enter a valid email address.
Password is required.
``` ### Multi-Step Form ```html
1
2
3
Personal Information
Contact Details
Review

Please review your information before submitting.

``` ## Form Utilities ### Floating Labels ```html
``` ### Form Helpers ```html
Your password must be 8-20 characters long.
``` ## JavaScript Form Handling ### Form Submission ```javascript // AJAX form submission async function submitForm(formElement) { const formData = new FormData(formElement); const data = Object.fromEntries(formData); try { const response = await fetch('/api/submit', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data) }); if (response.ok) { // Handle success showAlert('Form submitted successfully!', 'success'); formElement.reset(); } else { // Handle error showAlert('Submission failed. Please try again.', 'danger'); } } catch (error) { console.error('Error:', error); showAlert('Network error. Please check your connection.', 'danger'); } } ``` ### Dynamic Form Fields ```javascript // Add/remove form fields dynamically function addFormField(container, template) { const newField = template.cloneNode(true); container.appendChild(newField); } function removeFormField(button) { button.closest('.form-field').remove(); } ``` ## Accessibility - Always use labels with form controls - Provide clear error messages - Use fieldset and legend for grouped inputs - Ensure keyboard navigation works - Include aria-describedby for help text - Test with screen readers ## Best Practices ### DO: - Use appropriate input types - Provide clear labels and placeholders - Validate on both client and server - Show loading states during submission - Provide helpful error messages - Make forms mobile-friendly ### DON'T: - Don't rely only on color for feedback - Don't auto-focus without reason - Don't disable browser autofill - Don't use placeholder as label - Don't make forms too long