Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Update index.astro
Browse files Browse the repository at this point in the history
add the fetch functionality i think

Signed-off-by: Emperor Numerius <62899740+EmperorNumerius@users.noreply.github.com>
  • Loading branch information
EmperorNumerius authored May 28, 2024
1 parent 5bc4588 commit c6cd3b4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,41 @@ import Layout from "../layouts/Layout.astro";
margin-right: 0.5rem;
}
</style>
<script>
document.getElementById('subscribe-form').addEventListener('submit', async function(event) {
event.preventDefault();

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

const data = {
name: formData.get('name'),
email: formData.get('email'),
gdpr: formData.get('gdpr'),
hp: formData.get('hp'),
list: formData.get('list'),
subform: formData.get('subform')
};

try {
const response = await fetch('https://catapult.purplebubble.org/dashboard', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});

const result = await response.json();
if (response.ok) {
alert('Subscription successful');
} else {
console.error('Error:', result);
alert('Subscription failed');
}
} catch (error) {
console.error('Error:', error);
alert('An error occurred. Please try again.');
}
});
</script>

0 comments on commit c6cd3b4

Please sign in to comment.