Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/pages/subscribe.astro
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ const meta = {
required
autocomplete="email"
/>
<button type="submit" id="subscribe-btn" disabled>Subscribe</button>
<button type="submit" id="subscribe-btn">Subscribe</button>
<altcha-widget
id="altcha"
challengeurl="https://mailing.tylerrouze.com/api/public/captcha/altcha"
auto="onload"
hidefooter
></altcha-widget>
</form>
Expand All @@ -47,20 +48,11 @@ const meta = {
const btn = document.getElementById('subscribe-btn');
const result = document.getElementById('subscribe-result');

// Show the widget as soon as the user starts typing an email address.
// Show the widget once the user starts typing — it's already solving in the background.
emailInput.addEventListener('input', () => {
if (!widget.classList.contains('visible')) {
widget.classList.add('visible');
widget.setAttribute('auto', 'onload');
}
widget.classList.add('visible');
}, { once: true });

// Enable the submit button only after altcha has been solved.
// This closes the window where a bot could submit before the captcha fires.
widget.addEventListener('altcha-verified', () => {
btn.disabled = false;
});

form.addEventListener('submit', async (e) => {
e.preventDefault();

Expand Down