Fix newsletter forms: wire up footer form handler, fix FormSubmit string-truthy bug
All checks were successful
Build and Deploy to Storj / build-and-deploy (push) Successful in 13s
All checks were successful
Build and Deploy to Storj / build-and-deploy (push) Successful in 13s
This commit is contained in:
parent
7fa021b8af
commit
2f84d0f7a8
3 changed files with 78 additions and 4 deletions
|
|
@ -21,6 +21,50 @@ const currentYear = new Date().getFullYear();
|
|||
})();
|
||||
</script>
|
||||
|
||||
<!-- Footer newsletter form handler -->
|
||||
<script>
|
||||
(function() {
|
||||
const form = document.getElementById('footer-newsletter-form');
|
||||
if (!form) return;
|
||||
const successEl = form.parentElement.querySelector('.footer-newsletter-success');
|
||||
const errorEl = form.parentElement.querySelector('.footer-newsletter-error');
|
||||
const submitBtn = form.querySelector('button[type="submit"]');
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = 'Subscribing...';
|
||||
errorEl.style.display = 'none';
|
||||
errorEl.textContent = '';
|
||||
successEl.style.display = 'none';
|
||||
|
||||
try {
|
||||
const formData = new FormData(form);
|
||||
formData.append('_subject', 'Newsletter Subscribe - Scott Scoble');
|
||||
|
||||
const response = await fetch('https://formsubmit.co/ajax/scott@scoble.me', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok || result.success !== 'true') {
|
||||
throw new Error(result.message || 'Subscription failed. Please try again.');
|
||||
}
|
||||
|
||||
form.style.display = 'none';
|
||||
successEl.style.display = '';
|
||||
} catch (err) {
|
||||
errorEl.textContent = err.message || 'Something went wrong. Please try again.';
|
||||
errorEl.style.display = '';
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = 'Subscribe';
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<div class="footer-social">
|
||||
<a href="https://linkedin.com/in/scottscoble" target="_blank" rel="noopener" class="social-link" aria-label="Follow on LinkedIn for AI insights and leadership perspectives" data-umami-event="footer-linkedin-click">
|
||||
<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 01-2.063-2.065 2.064 2.064 0 112.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>
|
||||
|
|
@ -40,10 +84,17 @@ const currentYear = new Date().getFullYear();
|
|||
<div class="footer-newsletter">
|
||||
<h4>Stay in the loop</h4>
|
||||
<p>Get updates on new talks, workshops, and writings.</p>
|
||||
<form class="newsletter-form">
|
||||
<input type="email" placeholder="Your email" required />
|
||||
<form class="newsletter-form" id="footer-newsletter-form">
|
||||
<div style="position: absolute; left: -9999px;" aria-hidden="true">
|
||||
<input type="text" name="_gotcha" tabindex="-1" autocomplete="off" />
|
||||
</div>
|
||||
<input type="email" name="email" placeholder="Your email" required />
|
||||
<button type="submit">Subscribe</button>
|
||||
</form>
|
||||
<div class="footer-newsletter-success" style="display:none;">
|
||||
<p><strong>You're subscribed!</strong> Check your inbox for the welcome email.</p>
|
||||
</div>
|
||||
<div class="footer-newsletter-error" style="display:none;"></div>
|
||||
<p class="newsletter-note">No spam. Unsubscribe anytime.</p>
|
||||
</div>
|
||||
|
||||
|
|
@ -174,6 +225,29 @@ const currentYear = new Date().getFullYear();
|
|||
margin: 0 0 1rem;
|
||||
}
|
||||
|
||||
.footer-newsletter-success {
|
||||
text-align: center;
|
||||
padding: 1rem;
|
||||
background: rgba(61, 90, 62, 0.6);
|
||||
color: white;
|
||||
border-radius: 6px;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.footer-newsletter-success p {
|
||||
color: white;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.footer-newsletter-error {
|
||||
background: #dc2626;
|
||||
color: white;
|
||||
padding: 0.75rem;
|
||||
border-radius: 4px;
|
||||
font-size: 0.8125rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.newsletter-form {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ const topicParam = Astro.url.searchParams.get('topic');
|
|||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok || !result.success) {
|
||||
if (!response.ok || result.success === 'false' || !result.success) {
|
||||
throw new Error(result.message || 'Failed to send message. Please try again or email directly.');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ const {
|
|||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok || !result.success) {
|
||||
if (!response.ok || result.success === 'false' || !result.success) {
|
||||
throw new Error(result.message || 'Subscription failed. Please try again.');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue