-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
105 lines (92 loc) · 3.81 KB
/
index.html
File metadata and controls
105 lines (92 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Us - Formbase Example</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50 min-h-screen flex items-center justify-center px-4">
<div class="w-full max-w-md">
<h1 class="mb-2 text-center text-3xl font-bold text-gray-900">Contact Us</h1>
<p class="mb-8 text-center text-gray-600">Send us a message and we'll get back to you soon.</p>
<form id="contact-form" class="space-y-6">
<div>
<label for="name" class="block text-sm font-medium text-gray-700">Name</label>
<input
type="text"
id="name"
name="name"
required
class="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
<label for="email" class="block text-sm font-medium text-gray-700">Email</label>
<input
type="email"
id="email"
name="email"
required
class="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
<label for="message" class="block text-sm font-medium text-gray-700">Message</label>
<textarea
id="message"
name="message"
rows="4"
required
class="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
></textarea>
</div>
<p id="error-message" class="text-sm text-red-600 hidden"></p>
<button
type="submit"
id="submit-btn"
class="flex w-full items-center justify-center rounded-md bg-blue-600 px-4 py-2 text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed"
>
<svg id="spinner" class="mr-2 h-4 w-4 animate-spin hidden" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<span id="btn-text">Send Message</span>
</button>
</form>
</div>
<script>
const FORM_ID = 'YOUR_FORM_ID';
const form = document.getElementById('contact-form');
const submitBtn = document.getElementById('submit-btn');
const spinner = document.getElementById('spinner');
const btnText = document.getElementById('btn-text');
const errorMessage = document.getElementById('error-message');
form.addEventListener('submit', async (e) => {
e.preventDefault();
submitBtn.disabled = true;
spinner.classList.remove('hidden');
btnText.textContent = 'Sending...';
errorMessage.classList.add('hidden');
const formData = new FormData(form);
try {
const response = await fetch(`https://formbase.dev/s/${FORM_ID}`, {
method: 'POST',
body: formData,
});
if (!response.ok) {
throw new Error('Form submission failed');
}
window.location.href = 'thank-you.html';
} catch (error) {
errorMessage.textContent = 'Something went wrong. Please try again.';
errorMessage.classList.remove('hidden');
} finally {
submitBtn.disabled = false;
spinner.classList.add('hidden');
btnText.textContent = 'Send Message';
}
});
</script>
</body>
</html>