Autosubmit mailing list confirmation

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2026-03-12 15:14:00 +01:00
parent d1e0ec649a
commit 5ac6511f63
3 changed files with 15 additions and 8 deletions

View File

@@ -42,14 +42,17 @@ func confirmGetHandler() http.HandlerFunc {
renderPage(
w,
http.StatusOK,
// The confirmation should happen too quickly for the user to notice.
// This content is only shown as a fallback.
page{
Title: "Confirm subscription",
Heading: "Confirm your subscription",
Body: "Click the button below to confirm that you want to receive updates.",
Body: "Your confirmation should be processed automatically. If it isn’t, click the button below to confirm that you want to receive updates.",
Form: &form{
ActionURL: template.URL("?token=" + url.QueryEscape(token)),
Button: "Confirm subscription",
Danger: false,
ActionURL: template.URL("?token=" + url.QueryEscape(token)),
Button: "Confirm subscription",
AutoSubmit: true,
Danger: false,
},
},
)

View File

@@ -24,9 +24,10 @@ import (
var pageTmplHTML string
type form struct {
ActionURL template.URL
Button string
Danger bool
ActionURL template.URL
Button string
Danger bool
AutoSubmit bool
}
type page struct {

View File

@@ -88,11 +88,14 @@
<h1>{{.Heading}}</h1>
<p>{{.Body}}</p>
{{- if .Form}}
<form method="POST" action="{{.Form.ActionURL}}">
<form id="action-form" method="POST" action="{{.Form.ActionURL}}">
<button type="submit" class="{{if .Form.Danger}}danger{{else}}primary{{end}}">
{{.Form.Button}}
</button>
</form>
{{- if .Form.AutoSubmit}}
<script>document.getElementById("action-form").submit();</script>
{{- end}}
{{- end}}
</div>
</body>