-
-
Notifications
You must be signed in to change notification settings - Fork 681
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3458 from jspsych/docs-newsletter-signup
Add subscribe to newsletter page to docs
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 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 |
---|---|---|
@@ -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> |
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