-
Notifications
You must be signed in to change notification settings - Fork 2
/
contato.html
296 lines (254 loc) · 12.5 KB
/
contato.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
---
layout: default
title: Contato
---
<script>
function maskTel(input) {
value = input.value;
value = value.substring(0, 15);
value = value.replace(/\D/g, "")
value = value.replace(/^(\d\d)(\d)/g, "($1) $2")
value = value.replace(/(\d{4})(\d)/, "$1-$2")
document.getElementById(input.id).value = value;
}
function validateName(name) {
return name.length > 5 && name.length < 50;
}
function validateSubject(subject) {
return subject.length > 5 && subject.length < 50;
}
function validateEmail(email) {
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
function validatePhone(phone) {
const re = /^\(\d{2}\) \d{4}-\d{4,5}$/gi;
return re.test(String(phone).toLowerCase());
}
function validateMessage(message) {
return message.length > 10 && message.length < 250;
}
function validateAccessKey(key) {
const re = /\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/gm;
return re.test(String(key).toLowerCase());
}
function validValues() {
if (!validateAccessKey(document.getElementById('accessKey').value)) {
console.log('Chave inválida.')
return false;
}
if (!validateSubject(document.getElementById('subject').value)) {
console.log('Assunto inválido.')
return false;
}
if (!validateName(document.getElementById('name').value)) {
console.log('O nome deve ter entre 5 e 50 caracteres.')
return false;
}
if (!validateEmail(document.getElementById('email').value)) {
console.log('Email inválido.')
return false;
}
if (!validatePhone(document.getElementById('phone').value)) {
console.log('Telefone inválido.')
return false;
}
if (!validateMessage(document.getElementById('message').value)) {
const errorElement = document.getElementById('submitErrorMessage');
errorElement.innerHTML = 'A mensagem deve ter entre 10 e 250 caracteres.';
return false;
}
return true;
}
async function handleSubmit(form) {
const errorElement = document.getElementById('submitErrorBox');
errorElement.classList.add("d-none");
document.getElementById("submitFormBtn").setAttribute("disabled", 'true');
const formDataObj = Object.fromEntries(new FormData(form).entries());
if (!validValues()) {
errorElement.classList.remove("d-none");
document.getElementById("submitFormBtn").removeAttribute("disabled");
return false;
}
try {
const res = await fetch('https://api.staticforms.xyz/submit', {
method: 'POST',
body: JSON.stringify(formDataObj),
headers: {'Content-Type': 'application/json'}
});
const json = await res.json();
if (json.success) {
setTimeout(function () {
document.getElementById("modal").click();
document.getElementById("submitFormBtn").removeAttribute("disabled");
}, 3000);
} else {
console.log(json);
const errorElement = document.getElementById('submitErrorMessage');
errorElement.innerHTML = 'Ocorreu um erro no envio do formulário, atualize a página para tentar novamente ou volte mais tarde.';
document.getElementById("submitFormBtn").removeAttribute("disabled");
}
} catch (e) {
console.log('An error occurred', e);
const errorElement = document.getElementById('submitErrorMessage');
errorElement.innerHTML = 'Ocorreu um erro no envio do formulário, atualize a página para tentar novamente ou volte mais tarde.';
document.getElementById("submitFormBtn").removeAttribute("disabled");
}
}
</script>
<!-- Page content-->
<section class="py-5">
<div class="container px-5">
<!-- Contact form-->
<div class="bg-light rounded-3 py-5 px-4 px-md-5 mb-5">
<div class="text-center mb-5">
<div class="feature bg-primary bg-gradient text-white rounded-3 mb-3">
<i class="bi bi-envelope"></i>
</div>
<h1 class="fw-bolder">Formulário de contato</h1>
<p class="lead fw-normal text-muted mb-0">Esse é um formulário funcional gerado
com <a href="https://www.staticforms.xyz" class="link-primary text-decoration-none" target="_blank">
staticforms.xyz</a>!
</p>
</div>
<div class="row gx-5 justify-content-center">
<div class="col-lg-8 col-xl-6">
<!-- * * * * * * * * * * * * * * *-->
<!-- * * StaticForms Contact Form * *-->
<!-- * * * * * * * * * * * * * * *-->
<!-- This form is pre-integrated with StaticForms.-->
<!-- To make this form functional, sign up at-->
<!-- https://www.staticforms.xyz/-->
<!-- to get an API token!-->
<form id="staticform" onsubmit="handleSubmit(this); return false;">
<!-- Replace with your StaticForms accessKey -->
<input type="hidden" id="accessKey" name="accessKey" value="{{ site.staticforms_api_key }}">
<!-- If we receive data in this field submission will be ignored -->
<input type="text" name="honeypot" style="display: none;" value="only test">
<input type="hidden" id="subject" name="subject" value="Test jekyll-bootstrap">
<!-- Name input-->
<div class="form-floating mb-3">
<input class="form-control"
id="name"
name="name"
type="text"
placeholder="Seu nome..."
minlength="5"
maxlength="50" required>
<label for="name">Nome</label>
<div class="invalid-feedback"></div>
</div>
<!-- Email address input-->
<div class="form-floating mb-3">
<input class="form-control" id="email" name="email" type="email" required
placeholder="[email protected]">
<label for="email">E-mail</label>
<div class="invalid-feedback"></div>
</div>
<!-- Phone number input-->
<div class="form-floating mb-3">
<input class="form-control"
id="phone"
name="phone"
type="tel"
placeholder="(51) 3456-7890"
maxlength="15"
minlength="14"
onchange="maskTel(this)"
onkeyup="maskTel(this)"
onkeypress="maskTel(this)"
onautocomplete="maskTel(this)"
required>
<label for="phone">Telefone</label>
<div class="invalid-feedback"></div>
</div>
<!-- Message input-->
<div class="form-floating mb-3">
<textarea class="form-control"
id="message"
name="message"
type="text"
minlength="10"
maxlength="250"
required
placeholder="Entre com sua mensagem aqui..." style="height: 10rem"></textarea>
<label for="message">Mensagem</label>
<div class="invalid-feedback"></div>
</div>
<div class="alert alert-danger d-none" id="submitErrorBox" role="alert">
<div class="text-center text-danger" id="submitErrorMessage"></div>
</div>
<!-- Submit Button-->
<div class="d-grid">
<button class="btn btn-primary btn-lg btn-load-img" type="submit" id="submitFormBtn">
<img src="{{site.srcurl}}/assets/gifs/load_white.gif" class="d-none" height="28">
Enviar
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Contact cards-->
<div class="row gx-5 row-cols-2 row-cols-lg-4 py-5">
<div class="col">
<div class="feature bg-primary bg-gradient text-white rounded-3 mb-3">
<i class="bi bi-chat-dots"></i>
</div>
<div class="h5 mb-2">Icone 1</div>
<p class="text-muted mb-0">
Eu sou um parágrafo. Não sou nada de mais, apenas linhas. Várias e várias delas.
</p>
</div>
<div class="col">
<div class="feature bg-primary bg-gradient text-white rounded-3 mb-3"><i class="bi bi-people"></i></div>
<div class="h5">Icone 2</div>
<p class="text-muted mb-0">
Eu sou um parágrafo. Não sou nada de mais, apenas linhas. Várias e várias delas.
</p>
</div>
<div class="col">
<div class="feature bg-primary bg-gradient text-white rounded-3 mb-3">
<i class="bi bi-question-circle"></i>
</div>
<div class="h5">Icone 3</div>
<p class="text-muted mb-0">
Eu sou um parágrafo. Não sou nada de mais, apenas linhas. Várias e várias delas.
</p>
</div>
<div class="col">
<div class="feature bg-primary bg-gradient text-white rounded-3 mb-3">
<i class="bi bi-telephone"></i>
</div>
<div class="h5">Icone 4</div>
<p class="text-muted mb-0">
Eu sou um parágrafo. Não sou nada de mais, apenas linhas. Várias e várias delas.
</p>
</div>
</div>
</div>
</section>
<!-- Modal -->
<div class="modal fade" id="successModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="exampleModalLabel" aria-hidden="true" role="dialog">
<!-- Button trigger modal -->
<input type="hidden" id="modal" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#successModal">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Obrigado!</h5>
<a class="btn-close" href="{{site.srcurl}}/contato" title="Close"></a>
</div>
<div class="modal-body text-center mb-3">
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
<circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>
<path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>
<p class="lead py-3 px-2">Formulário de contato enviado com sucesso. Obrigado, entraremos em contato com
você em
breve! Este é um exemplo de mensagem.</p>
<a class="btn btn-primary" href="{{site.srcurl}}/" title="Voltar a home">Voltar a home!</a>
</div>
</div>
</div>
</div>