prototip / index.html
SergTsn's picture
создать форму обратной связи: имя,телефон, электронная почта - Initial Deployment
19bafd2 verified
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Форма обратной связи</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.shake {
animation: shake 0.5s;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
20%, 40%, 60%, 80% { transform: translateX(5px); }
}
.success-message {
opacity: 0;
transform: translateY(20px);
transition: all 0.3s ease;
}
.success-message.show {
opacity: 1;
transform: translateY(0);
}
.input-highlight {
position: absolute;
bottom: 0;
left: 0;
height: 2px;
width: 0;
background-color: #3b82f6;
transition: width 0.3s ease;
}
.input-container:focus-within .input-highlight {
width: 100%;
}
</style>
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center p-4">
<div class="w-full max-w-md">
<div class="bg-white rounded-xl shadow-2xl overflow-hidden">
<div class="bg-gradient-to-r from-blue-500 to-indigo-600 p-6 text-white">
<h1 class="text-2xl font-bold">Свяжитесь с нами</h1>
<p class="opacity-90">Заполните форму, и мы ответим вам в ближайшее время</p>
</div>
<form id="feedbackForm" class="p-6 space-y-6">
<div class="input-container relative">
<div class="flex items-center mb-1">
<i class="fas fa-user text-gray-400 mr-2"></i>
<label for="name" class="block text-sm font-medium text-gray-700">Ваше имя</label>
</div>
<input type="text" id="name" name="name"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-200 transition"
placeholder="Иван Иванов">
<div class="input-highlight"></div>
<div id="nameError" class="text-red-500 text-xs mt-1 h-4"></div>
</div>
<div class="input-container relative">
<div class="flex items-center mb-1">
<i class="fas fa-phone text-gray-400 mr-2"></i>
<label for="phone" class="block text-sm font-medium text-gray-700">Телефон</label>
</div>
<input type="tel" id="phone" name="phone"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-200 transition"
placeholder="+7 (999) 123-45-67">
<div class="input-highlight"></div>
<div id="phoneError" class="text-red-500 text-xs mt-1 h-4"></div>
</div>
<div class="input-container relative">
<div class="flex items-center mb-1">
<i class="fas fa-envelope text-gray-400 mr-2"></i>
<label for="email" class="block text-sm font-medium text-gray-700">Электронная почта</label>
</div>
<input type="email" id="email" name="email"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-200 transition"
placeholder="example@mail.com">
<div class="input-highlight"></div>
<div id="emailError" class="text-red-500 text-xs mt-1 h-4"></div>
</div>
<div class="pt-2">
<button type="submit"
class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-3 px-4 rounded-lg transition duration-300 flex items-center justify-center">
<span id="submitText">Отправить</span>
<i id="submitIcon" class="fas fa-paper-plane ml-2"></i>
<i id="loadingIcon" class="fas fa-spinner fa-spin ml-2 hidden"></i>
</button>
</div>
</form>
<div id="successMessage" class="success-message p-6 text-center hidden">
<div class="inline-flex items-center justify-center w-16 h-16 bg-green-100 rounded-full mb-4">
<i class="fas fa-check text-green-500 text-2xl"></i>
</div>
<h3 class="text-xl font-bold text-gray-800 mb-2">Спасибо!</h3>
<p class="text-gray-600">Ваше сообщение успешно отправлено. Мы свяжемся с вами в ближайшее время.</p>
<button id="resetForm" class="mt-6 text-blue-600 font-medium hover:text-blue-800 transition">
Отправить еще одно сообщение
</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('feedbackForm');
const successMessage = document.getElementById('successMessage');
const resetFormBtn = document.getElementById('resetForm');
const submitText = document.getElementById('submitText');
const submitIcon = document.getElementById('submitIcon');
const loadingIcon = document.getElementById('loadingIcon');
// Маска для телефона
const phoneInput = document.getElementById('phone');
phoneInput.addEventListener('input', function(e) {
let x = e.target.value.replace(/\D/g, '').match(/(\d{0,1})(\d{0,3})(\d{0,3})(\d{0,2})(\d{0,2})/);
e.target.value = !x[2] ? x[1] : x[1] + ' (' + x[2] + ') ' + x[3] + (x[4] ? '-' + x[4] : '') + (x[5] ? '-' + x[5] : '');
});
form.addEventListener('submit', function(e) {
e.preventDefault();
// Валидация
let isValid = true;
const name = document.getElementById('name');
const phone = document.getElementById('phone');
const email = document.getElementById('email');
// Валидация имени
if (name.value.trim() === '') {
document.getElementById('nameError').textContent = 'Пожалуйста, введите ваше имя';
name.classList.add('border-red-500');
name.classList.add('shake');
isValid = false;
setTimeout(() => name.classList.remove('shake'), 500);
} else {
document.getElementById('nameError').textContent = '';
name.classList.remove('border-red-500');
}
// Валидация телефона
const phoneRegex = /^\+?\d{1}?\s?\(?\d{3}\)?\s?\d{3}-?\d{2}-?\d{2}$/;
if (!phoneRegex.test(phone.value)) {
document.getElementById('phoneError').textContent = 'Пожалуйста, введите корректный номер телефона';
phone.classList.add('border-red-500');
phone.classList.add('shake');
isValid = false;
setTimeout(() => phone.classList.remove('shake'), 500);
} else {
document.getElementById('phoneError').textContent = '';
phone.classList.remove('border-red-500');
}
// Валидация email
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email.value)) {
document.getElementById('emailError').textContent = 'Пожалуйста, введите корректный email';
email.classList.add('border-red-500');
email.classList.add('shake');
isValid = false;
setTimeout(() => email.classList.remove('shake'), 500);
} else {
document.getElementById('emailError').textContent = '';
email.classList.remove('border-red-500');
}
if (isValid) {
// Показываем индикатор загрузки
submitText.textContent = 'Отправка...';
submitIcon.classList.add('hidden');
loadingIcon.classList.remove('hidden');
// Имитация отправки на сервер
setTimeout(() => {
// Скрываем форму, показываем сообщение об успехе
form.classList.add('hidden');
successMessage.classList.remove('hidden');
successMessage.classList.add('show');
// Восстанавливаем кнопку
submitText.textContent = 'Отправить';
submitIcon.classList.remove('hidden');
loadingIcon.classList.add('hidden');
}, 1500);
}
});
resetFormBtn.addEventListener('click', function() {
// Скрываем сообщение об успехе, показываем форму
successMessage.classList.remove('show');
setTimeout(() => {
successMessage.classList.add('hidden');
form.classList.remove('hidden');
form.reset();
}, 300);
});
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=SergTsn/prototip" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>