This modern survey form features a clean, minimalist design with a responsive layout that works seamlessly on both mobile and desktop devices. It includes all required form fields—such as text inputs, radio buttons, checkboxes, and a dropdown—with proper validation to ensure users complete mandatory fields before submission. The form provides visual feedback with error messages and a success notification, all without page reloads, creating a smooth and user-friendly experience.
:root {
--primary-color: #4a6bff;
--secondary-color: #f5f7ff;
--text-color: #333;
--light-gray: #f0f2f5;
--border-radius: 8px;
--box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
line-height: 1.6;
color: var(--text-color);
background-color: var(--light-gray);
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 30px;
background-color: white;
border-radius: var(--border-radius);
box-shadow: var(--box-shadow);
}
h1 {
text-align: center;
margin-bottom: 30px;
font-weight: 600;
color: var(--primary-color);
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 500;
}
input[type="text"],
input[type="email"],
input[type="number"],
select,
textarea {
width: 100%;
padding: 12px 15px;
border: 1px solid #ddd;
border-radius: var(--border-radius);
font-family: inherit;
font-size: 16px;
transition: border-color 0.3s;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 2px rgba(74, 107, 255, 0.2);
}
textarea {
min-height: 120px;
resize: vertical;
}
.radio-group, .checkbox-group {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin-top: 10px;
}
.radio-option, .checkbox-option {
display: flex;
align-items: center;
}
.radio-option input, .checkbox-option input {
margin-right: 8px;
}
.range-slider {
width: 100%;
margin-top: 10px;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 5px;
font-size: 14px;
color: #666;
}
button {
display: block;
width: 100%;
padding: 14px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: var(--border-radius);
font-size: 16px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s;
margin-top: 30px;
}
button:hover {
background-color: #3a5bef;
transform: translateY(-2px);
box-shadow: 0 6px 12px rgba(74, 107, 255, 0.2);
}
.success-message {
display: none;
text-align: center;
padding: 20px;
background-color: #e8f5e9;
color: #2e7d32;
border-radius: var(--border-radius);
margin-top: 20px;
}
.error {
color: #d32f2f;
font-size: 14px;
margin-top: 5px;
display: none;
}
@media (max-width: 600px) {
.container {
padding: 20px;
}
.radio-group, .checkbox-group {
flex-direction: column;
gap: 10px;
}
}
document.getElementById('surveyForm').addEventListener('submit', function(e) {
e.preventDefault();
// Reset errors
document.querySelectorAll('.error').forEach(el => el.style.display = 'none');
// Validate form
let isValid = true;
// Name validation
const name = document.getElementById('fullName').value.trim();
if (!name) {
document.getElementById('nameError').style.display = 'block';
isValid = false;
}
// Email validation
const email = document.getElementById('email').value.trim();
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!email || !emailRegex.test(email)) {
document.getElementById('emailError').style.display = 'block';
isValid = false;
}
// Satisfaction validation
const satisfaction = document.getElementById('satisfaction').value;
if (!satisfaction) {
document.getElementById('satisfactionError').style.display = 'block';
isValid = false;
}
if (isValid) {
// Form is valid - show success message
document.getElementById('surveyForm').style.display = 'none';
document.getElementById('successMessage').style.display = 'block';
// In a real app, you would send the data to a server here
// const formData = new FormData(this);
// fetch('/submit-survey', { method: 'POST', body: formData })
// .then(response => response.json())
// .then(data => {
// document.getElementById('surveyForm').style.display = 'none';
// document.getElementById('successMessage').style.display = 'block';
// });
}
});
Post a Comment
Thank you
Learning robo team