Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion assets/contact/contact.css
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ textarea {
color: #4a90e2;
}

#error {
color: #e74c3c;
font-size: 21px;
}

#success {
color: #4a90e2;
font-size: 21px;
}

/* Footer Css*/

footer {
Expand Down Expand Up @@ -168,4 +178,4 @@ footer {
footer {
font-size: 0.9em;
}
}
}
1 change: 1 addition & 0 deletions assets/contact/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ <h1>CONTACT US</h1>
<i class="fas fa-chevron-up"></i>
</a>

<script src="contact.js"></script>
<script src="../../script.js"></script>
</body>

Expand Down
24 changes: 24 additions & 0 deletions assets/contact/contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const submitAjaxForm = event => {
event.preventDefault()

let form = event.target
const formData = new FormData(form)

fetch("/", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams(formData).toString()
})
.then(response => {
if (!response.ok) {
form.innerHTML = `<h1 id='error'>Oops! We encountered an error. <br>Please try again later.</h1>`
} else {
form.innerHTML = `<h1 id='success'>Thanks for reaching out! <br>I will get back to you shortly.</h1>`
}
})
.catch(error => {
form.innerHTML = `<h1 id='error'>Oops! We encountered an error. <br>Please try again later.</h1>`
})
}

document.querySelector("form").addEventListener("submit", submitAjaxForm);
Loading