-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
157 lines (140 loc) · 4.75 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!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">
<!-- Bootstrap link -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- <link rel="stylesheet" href="style.css"> -->
<title>Contact Form</title>
</head>
<body>
<style>
body {
background-color: #f2f2f2;
font-family: Arial, Helvetica, sans-serif;
}
.container {
background-color: #fff;
width: 500px;
margin-top: 20px;
/* margin: 0 auto; */
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.contact-box form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.container h1 {
text-align: center;
text-transform: uppercase;
color: #333;
}
.container form {
margin-top: 20px;
}
.container form .form-control {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.container form .form-control:focus {
outline: none;
border-color: #333;
}
.container form .form-control.error {
border-color: #f00;
}
.container form .error-text {
color: #f00;
font-size: 12px;
}
.container form .btn {
width: 100%;
padding: 10px;
margin-top: 20px;
border: none;
border-radius: 5px;
background-color: #333;
color: #fff;
cursor: pointer;
font-size: 16px;
text-transform: uppercase;
}
.container form .btn:hover {
background-color: #555;
}
.container form .success-text {
color: #0f0;
font-size: 12px;
}
form input[type="text"],textarea,
#sub{
background-color: #333;
color: #fff;
cursor: pointer;
font-size: 16px;
text-transform: uppercase;
width: 50%;
padding: 10px;
margin-top: 20px;
border: none;
border-radius: 5px;
}
#sub:hover{
background-color: #555;
}
/* Success message div */
#successmsg, #errormsg{
margin-top: 10px;
}
@media (max-width: 500px) {
.container {
width: 100%;
}
}
</style>
<div class="container">
<div class="contact-box">
<center><h2>Contact Us</h2></center>
<form name="submit-to-google-sheet">
<input type="text" class="field" placeholder="Name" name="name" required>
<input type="text" class="field" placeholder="Email" name="email" required>
<input type="text" class="field" placeholder="Subject" id="sub" name ="subject" required>
<textarea placeholder="Message" class="field" name="message" required></textarea>
<input type="submit" class="btn" value="Send">
</form>
</div>
<div id="successmsg" hidden><div class="alert alert-success">
<strong>Success!</strong> Your message has been sent.
</div></div>
<div id="errormsg" hidden><div class="alert alert-danger">
<strong>Error!</strong> There was an error sending your message.
</div></div>
</div>
<script>
const scriptURL = 'https://script.google.com/macros/s/AKfycbyJekf24Ul5OLqzN5p5GuopqYf2eUp6o9h6i4SEISCxOrTU1CEVNbu9Fg66JhN4PiIK/exec'
const form = document.forms['submit-to-google-sheet'];
const successmsg=document.getElementById('successmsg');
const errormsg=document.getElementById('errormsg');
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => console.log('Success!', response),
//show success message
successmsg.hidden=false
)
.catch(error => errormsg.hidden=false)
//show error message
form.reset();
})
</script>
</body>
</html>