contact

package
v0.0.0-...-963cf5d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: GPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contact renders and checks the ContactForm element: a form built from the Contact{} block of app.sml (see CWUP/tasks/contact_newsletter.md). The form posts to the page it is on; internal/server mails the result and hands a ticked newsletter box to internal/newsletter.

Index

Constants

View Source
const (
	HoneypotField = "_website"
	StampField    = "_ts"   // signed time the form was shown, see internal/server/contact.go
	MarkerField   = "_form" // tells a ContactForm POST from other POSTs to a page
	MarkerValue   = "contact"
)

Form field names used by the form itself (not by Contact{} fields).

View Source
const (
	MaxValueLen    = 500
	MaxTextareaLen = 10000
)

Limits per value.

Variables

This section is empty.

Functions

func Render

func Render(d FormData) (template.HTML, error)

Render renders the ContactForm element.

func T

func T(lang, key string) string

T returns the text for key in lang, falling back to English.

Types

type FieldView

type FieldView struct {
	ID       string // HTML id
	Name     string
	Type     string
	Label    string
	Required bool
	Value    string
	Checked  bool // single checkbox / newsletter
	Options  []Option
}

FieldView is a field prepared for the form.

func Fields

func Fields(fields []config.ContactField, lang string, values url.Values, newsletter bool) []FieldView

Fields prepares the configured fields for lang with the submitted values (nil for an empty form). Newsletter fields are dropped unless newsletter is true.

type FormData

type FormData struct {
	Lang    string
	Title   string
	Submit  string
	Privacy string // newsletter privacy link
	Fields  []FieldView
	Errors  []string
	Sent    bool
	Success string
	Notes   []string // extra lines after success (newsletter confirmation)
	Stamp   string   // value of StampField
}

FormData feeds the ContactForm element.

type Option

type Option struct {
	Value   string
	Label   string
	Checked bool
}

Option is one choice of a checkbox/radio/select field.

type Row

type Row struct {
	Label string
	Value string
}

Row is one label/value pair of a submission, for the notification mail.

type Submission

type Submission struct {
	Rows       []Row
	Email      string // value of the first email field ("" if none)
	Newsletter bool   // a newsletter box was ticked
}

Submission is a checked form post.

func Parse

func Parse(fields []config.ContactField, form url.Values, lang, mailLang string, newsletter bool, validEmail func(string) bool) (Submission, []string)

Parse checks a submission against the configured fields. Labels in the result are in mailLang (the site owner's language), error messages in lang. validEmail decides what counts as an email address.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL