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

Commit

Permalink
should work now
Browse files Browse the repository at this point in the history
  • Loading branch information
EmperorNumerius authored May 29, 2024
1 parent 9382e19 commit c990743
Showing 1 changed file with 23 additions and 39 deletions.
62 changes: 23 additions & 39 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
---
import Layout from "../layouts/Layout.astro";
let error;
if (Astro.request.method === "POST") {
try {
const data = await Astro.request.formData();
const name = data.get("name");
const email = data.get("email”);
const response = await fetch('https://catapult.purplebubble.org/api/subscribe', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body = JSON.stringify({ name: name, email: email})
});
}
catch (error) {
if (error instanceof Error) {
{
error && (
<p class="text-red-500">Error: {error}</p>
)
}
}
}
---
<Layout title="Purple Bubble" fiscalSponsor="true">
Expand Down Expand Up @@ -93,42 +116,3 @@ 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 = {
email: formData.get('email'),
name: formData.get('name')
//gdpr: formData.get('gdpr'),
//hp: formData.get('hp'),
//list: formData.get('list'),
//subform: formData.get('subform')
};
//body: JSON.stringify({ email: '[email protected]', name: 'Example User' }),

try {
const response = await fetch('https://purplebubblewebsite.netlify.app/api/subscribe', {
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 c990743

Please sign in to comment.