This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9382e19
commit c990743
Showing
1 changed file
with
23 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> | ||
|
@@ -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> |