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 ¶
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).
const ( MaxValueLen = 500 MaxTextareaLen = 10000 )
Limits per value.
Variables ¶
This section is empty.
Functions ¶
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.
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 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.