-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
53 lines (50 loc) · 2.65 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<title>HTML Form to Google Sheets - Pure Coding</title>
</head>
<body>
<div class="container py-5">
<div class="row">
<div class="col-lg-5 col-md-8 mx-auto shadow border bg-white p-4 rounded">
<h2 class="text-center fw-bold mb-3">Contact Us</h2>
<form name="google-sheet">
<div id="form_alerts"></div>
<div class="form-group mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" id="name" name="name" class="form-control" placeholder="Enter your name" required>
</div>
<div class="form-group mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" id="email" name="email" class="form-control" placeholder="Enter your email address" required>
</div>
<div class="form-group mb-3">
<label for="message" class="form-label">Message</label>
<textarea id="message" name="message" class="form-control" placeholder="Enter your message" rows="5" required></textarea>
</div>
<div>
<button class="btn btn-primary me-2" type="submit">Send message!</button>
<button class="btn btn-danger" type="reset">Reset the form!</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>
const scriptURL = 'https://script.google.com/macros/s/AKfycby-HKWWxeRXl0d8t4J3MeJeNpcWh2sXMZcYm5Sezoswv_DLyAtK-nrkKR2UebrHUP6H/exec'
const form = document.forms['google-sheet']
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => $("#form_alerts").html("<div class='alert alert-success'>Contact message sent successfully.</div>"))
.catch(error => $("#form_alerts").html("<div class='alert alert-danger'>Contact message not sent.</div>"))
})
</script>
</body>
</html>