Files
thistleandmoth-site/layouts/partials/course-enroll-form.html
T
will b39dcda4a1
deploy / deploy (push) Successful in 5s
Initial scaffold: submissions page + reader-magnet stub
Mirrors twosquirrelspress-site's submissions form and
michaelferrara-site's gift/course-enroll pattern. Gift page content,
cover art, and the download file are stubs until the real
reader-magnet is ready.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-16 12:02:47 -04:00

56 lines
2.2 KiB
HTML

{{ $id := .id }}
{{ $page := .page }}
<form id="enroll-form-{{ $id }}" class="enroll-form">
<label for="email-{{ $id }}">Email</label>
<input type="email" id="email-{{ $id }}" name="email" required autocomplete="email" placeholder="you@example.com">
<div class="field-honeypot" aria-hidden="true">
<label for="website-{{ $id }}">Leave this field empty</label>
<input type="text" id="website-{{ $id }}" name="website" tabindex="-1" autocomplete="off">
</div>
<button type="submit" class="btn">{{ $page.Params.cta_text | default "Send me the story" }}</button>
</form>
<p id="enroll-status-{{ $id }}" role="status" class="enroll-status"></p>
{{ with $page.Params.download_url }}
<p id="enroll-download-{{ $id }}" class="enroll-download" hidden>
<a class="btn" href="{{ . }}">{{ $page.Params.download_text | default "Download now" }}</a>
</p>
{{ end }}
<script>
(function () {
var form = document.getElementById("enroll-form-{{ $id }}");
var status = document.getElementById("enroll-status-{{ $id }}");
var download = document.getElementById("enroll-download-{{ $id }}");
var slug = {{ $page.Params.eec_slug }};
form.addEventListener("submit", function (e) {
e.preventDefault();
if (form.website.value) return; // honeypot
var submitBtn = form.querySelector("button[type=submit]");
submitBtn.disabled = true;
status.textContent = "Signing you up…";
fetch("{{ $page.Site.Params.eec_base_url }}/courses/" + slug + "/enroll", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email: form.email.value })
}).then(function (res) {
if (res.ok) {
form.reset();
form.hidden = true;
status.textContent = "It's on its way to your inbox too — check your email for the link.";
if (download) download.hidden = false;
return;
}
return res.text().then(function (msg) {
submitBtn.disabled = false;
status.textContent = msg || "Something went wrong. Try again in a moment.";
});
}).catch(function () {
submitBtn.disabled = false;
status.textContent = "Something went wrong. Try again in a moment.";
});
});
})();
</script>