-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.html
More file actions
88 lines (81 loc) · 3.73 KB
/
message.html
File metadata and controls
88 lines (81 loc) · 3.73 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact - Xinping Song</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/styles.css">
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 dark:bg-gray-900">
<nav>
<a href="index.html#about">About</a>
<a href="index.html#projects">Projects</a>
<a href="index.html#skills">Skills</a>
<a href="index.html#contact">Contact</a>
<a href="message.html">Message</a>
</nav>
<div class="container mx-auto mt-10">
<div class="max-w-xl mx-auto bg-white p-5 rounded-md shadow-sm">
<div class="text-center">
<h1 class="my-3 text-3xl font-semibold text-gray-700 dark:text-gray-200">Contact Me</h1>
<p class="text-gray-400 dark:text-gray-400">Fill up the form below to send me a message.</p>
</div>
<div class="m-7">
<form action="https://api.web3forms.com/submit" method="POST" id="contact-form">
<input type="hidden" name="access_key" value="3c43445c-6481-4f38-983e-b3917ca1c99a" />
<input type="hidden" name="subject" value="New Submission from Contact Form" />
<label for="email" class="block mb-2 text-sm text-gray-600 dark:text-gray-400">Email Address</label>
<input type="email" name="email" id="email" placeholder="you@company.com" required class="w-full px-3 py-2 border-2 rounded-md focus:outline-none focus:ring focus:ring-indigo-100 focus:border-indigo-300" />
<label for="message" class="block mt-4 mb-2 text-sm text-gray-600 dark:text-gray-400">Your Message</label>
<textarea rows="5" name="message" id="message" placeholder="Your Message" required class="w-full px-3 py-2 border-2 rounded-md focus:outline-none focus:ring focus:ring-indigo-100 focus:border-indigo-300"></textarea>
<button type="submit" class="w-full mt-4 px-3 py-4 text-white bg-indigo-500 rounded-md focus:bg-indigo-600 focus:outline-none">Send Message</button>
</form>
<p class="text-center text-gray-400 mt-4" id="form-response"></p>
</div>
</div>
</div>
<script>
document.getElementById('contact-form').addEventListener('submit', function(event) {
event.preventDefault();
const formData = new FormData(this);
fetch('https://api.web3forms.com/submit', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(Object.fromEntries(formData))
})
.then(response => response.json())
.then(data => {
document.getElementById('form-response').innerText = 'Message sent successfully!';
this.reset();
})
.catch(error => {
document.getElementById('form-response').innerText = 'Error sending message. Please try again later.';
});
});
</script>
</body>
</html>
<script>
document.getElementById('contact-form').addEventListener('submit', function(event) {
event.preventDefault();
const formData = new FormData(this);
fetch('https://api.web3forms.com/submit', {
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById('form-response').innerText = '✅ Message sent successfully!';
document.getElementById('contact-form').reset();
} else {
document.getElementById('form-response').innerText = '❌ Error sending message. Try again.';
}
})
.catch(error => {
document.getElementById('form-response').innerText = '⚠ Network error. Please check your internet.';
});
});
</script>