Skip to content

Commit

Permalink
disable the subscribe button while waiting for subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
jodeleeuw committed Dec 16, 2024
1 parent 4303c91 commit 0675ff5
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions docs/newsletter/subscribe.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,33 @@ You can unsubscribe at any time.
return true;
}

function submitForm() {

async 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");
const subscribeButton = document.querySelector('button#subscribe');

fetch(url, {
method: 'POST',
headers: {
// Disable the subscribe button
subscribeButton.disabled = true;

try {
const response = await 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)
},
body: new URLSearchParams(new FormData(document.getElementById('subscribeform'))),
});

const data = await response.text();
resultDiv.innerHTML = successMessage;
})
.catch(error => {
} catch (error) {
resultDiv.innerHTML = 'An error occurred. Please try again later.';
});
} finally {
// Re-enable the subscribe button
subscribeButton.disabled = false;
}
}

document.querySelector('button#subscribe').addEventListener('click', submitForm);
Expand Down

0 comments on commit 0675ff5

Please sign in to comment.