Skip to content

Commit

Permalink
add newsletter subscribe page
Browse files Browse the repository at this point in the history
  • Loading branch information
jodeleeuw committed Dec 15, 2024
1 parent 334c9d7 commit 291772c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
61 changes: 61 additions & 0 deletions docs/newsletter/subscribe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Subscribe to our newsletter

Subscribe to our newsletter to stay up to date with the latest news and updates from the jsPsych team.
We send out newsletters about once a month.
The newsletter includes information about new releases, upcoming events, community spotlights, and other news related to jsPsych.
You can unsubscribe at any time.


<form method="post" name="subscribeform" id="subscribeform" enctype="multipart/form-data">
<input type="email" name="email" placeholder="Email address" id="email" size="40" class="md-input" required>
<input type="hidden" name="htmlemail" value="1">
<input type="hidden" name="list[2]" value="signup" />
<input type="hidden" name="subscribe" value="subscribe"/>
<button class='md-button md-button--primary' onclick="if (checkform()) {submitForm();} return false;" >Subscribe</button>
<div id="result" style="color: red;"></div>
</form>

<script type="text/javascript">

function checkform() {
const re = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const emailInput = document.getElementById("email");
const resultDiv = document.getElementById("result");

if (!re.test(emailInput.value)) {
resultDiv.innerHTML = "Please enter a valid email address";
emailInput.focus();
return false;
}
return true;
}

function submitForm() {

const emailInput = document.getElementById("email");
const successMessage = 'Thank you for your registration. Please check your email to confirm.';
const url = 'https://mail.jspsych.org/?p=asubscribe&id=6';
const resultDiv = document.getElementById("result");

fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded', // Adjust based on your content type
},
body: new URLSearchParams(new FormData(document.getElementById('subscribeform'))),
})
.then(async response => {
const r = await response.text();
console.log(r);
})
.then(data => {
console.log(data)
resultDiv.innerHTML = successMessage;
})
.catch(error => {
resultDiv.innerHTML = 'An error occurred. Please try again later.';
});
}

document.querySelector('button#subscribe').addEventListener('click', submitForm);
</script>
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,5 @@ nav:
- About:
- 'About jsPsych': 'about/about.md'
- 'License': 'about/license.md'
- Newsletter:
- 'Subscribe': 'newsletter/subscribe.md'

0 comments on commit 291772c

Please sign in to comment.