Skip to content

Commit

Permalink
Test Using Email with Formspree
Browse files Browse the repository at this point in the history
  • Loading branch information
PydevAzmi committed Jul 7, 2024
1 parent 63bb70d commit 8fd61d8
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,50 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
<title></title>
</head>
<body>
<h1>hi</h1>
<form id="my-form" action="https://formspree.io/f/mpwazbgv" method="POST">
<label>Email:</label>
<input type="email" name="email" />
<label>Message:</label>
<input type="text" name="message" />
<button id="my-form-button">Submit</button>
<p id="my-form-status"></p>
</form>

<script>
var form = document.getElementById("my-form");

async function handleSubmit(event) {
event.preventDefault();
var status = document.getElementById("my-form-status");
var data = new FormData(event.target);
fetch(event.target.action, {
method: form.method,
body: data,
headers: {
'Accept': 'application/json'
}
}).then(response => {
if (response.ok) {
status.innerHTML = "Thanks for your Message!";
form.reset()
} else {
response.json().then(data => {
if (Object.hasOwn(data, 'errors')) {
status.innerHTML = data["errors"].map(error => error["message"]).join(", ")
} else {
status.innerHTML = "Oops! There was a problem submitting your form"
}
})
}
}).catch(error => {
status.innerHTML = "Oops! There was a problem submitting your form"
});
}
form.addEventListener("submit", handleSubmit)
</script>

</body>
</html>
</html>

0 comments on commit 8fd61d8

Please sign in to comment.