Skip to content

Commit 60b9c6f

Browse files
Commit
1 parent 7c71aa3 commit 60b9c6f

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

images/favicon.ico

2.1 KB
Binary file not shown.

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ <h1 class="title">Feel the rhythm.</h1>
3838
Join the waitlist!
3939
</button>
4040
</form>
41+
<script src="waitlist.js"></script>
4142
</div>
4243
</div>
4344
</div>

waitlist.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
document.getElementById('waitlist-form').addEventListener('submit', function(e) {
2+
e.preventDefault();
3+
4+
const form = e.target;
5+
const formData = new FormData(form);
6+
7+
fetch(form.action, {
8+
method: form.method,
9+
body: formData,
10+
headers: {
11+
'Accept': 'application/json'
12+
}
13+
}).then(response => {
14+
if (response.ok) {
15+
form.reset();
16+
alert('Thanks for joining the waitlist!');
17+
} else {
18+
response.json().then(data => {
19+
if (Object.hasOwn(data, 'errors')) {
20+
alert(data["errors"].map(error => error["message"]).join(", "));
21+
} else {
22+
alert('Oops! There was a problem submitting your form.');
23+
}
24+
});
25+
}
26+
}).catch(error => {
27+
alert('Oops! There was a problem submitting your form.');
28+
});
29+
});

0 commit comments

Comments
 (0)