Scaffold michaelferrara-site: Hugo skeleton with reader-magnet freebie flow
deploy / deploy (push) Successful in 4s
deploy / deploy (push) Successful in 4s
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
{{ $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>
|
||||
Reference in New Issue
Block a user