Releases: torrayne/formailer
Update Username
- Update github username
Upgrade Go
- Upgrade to Go 1.22
Fix custom configs
Update built-in handlers
- Add logging to built-in handlers
- Change response type to JSON
- Clarify some errors
More Polish
New New
function
This update removes even more boilerplate with the New
function. This function creates a new form using an ID, initializes the ignore
map, ignores the form name and reCAPTCHA fields, and adds the form to the default config.
The new quickstart looks like this:
contact := formailer.New("Contact")
contact.AddEmail(formailer.Email{
To: "[email protected]",
From: `"Company" <[email protected]>`,
Subject: "New Contact Submission",
})
handlers.Vercel(formailer.DefaultConfig, w, r)
New Ignore
function
I've replaced the Form.Ignore
array with a function. The logic is still the same but the flow is just a little better.
Documentation
I've gone through everything adding comments explaining why a something exists and how it's used. Hopefully this makes it easier to pickup and learn.
Recaptcha Fix
reCAPTCHA broke in the previous release when running without recaptcha. And until now simply not submitting the g-recaptcha-response
field would bypass the verification check. This update fixes both of those issues with a new setting: Form.ReCAPTCHA
.
QoL & Polish
The map[string][]Email
map has been replaced with map[string]Form
. This way we can add settings to a form that shouldn't be set per email. Right now the only options are Redirect
and Ignore
.
- If
Redirect
is set the builit-in handlers will send a 303 SeeOther response. Ignore
is used for when buildingSubmission.Order
. This is an easy way to prevent rendering certain fields when ranging over the submission's values. IfIgnore
isnil
it defaults to_form_name
andg-recaptcha-response
.
Submission now comes with an Order
field which is a slice of keys you can use when rendering your template. This is how you render your fields in the same order they were submitted in. Just ranging over the Values
map render in alphabetical order.
The Add
function has been moved to Form
and renamed AddEmail
. Since it's a method of Form
you don't need to pass the form name anymore.
You no longer need to call make(formailer.Forms)
. Formailer now comes with a default config. The non method versions of Add
and Parse
will run on DefaultConfig
. But if you would like to have multiple configs that's fine too. Just call make(formailer.Config)
and use your new config when calling Add
and Parse
.
Some fields should always be a string; like _form_name
. There is now a forceString function that is run with parseURLEncoded
and parseMultipart
.
The Content-Type header is now being parsed by mime.ParseMediaType
. And it handles parsing the boundary for multipart forms as well.
We're back to Go 1.16.x with embedding the default template now that I can test with Vercel locally again.
The new example implementations look like this:
// Formailer handles all form submissions
func Formailer(w http.ResponseWriter, r *http.Request) {
contact := formailer.Form{Name: "Contact"}
contact.AddEmail(formailer.Email{
ID: "contact",
To: "[email protected]",
From: `"Company" <[email protected]>`,
Subject: "New Contact Submission",
})
formailer.Add(contact)
handlers.Vercel(formailer.DefaultConfig, w, r)
}
Save each form to a variable to use the AddEmail
function. Then right before you call your handler, Add
all your forms.
Full control over emails
You can now set CC
, BCC
, and Reply-To
fields in your Email
config.
The mail.Email
is now also exposed using email.Email()
. This gives you full control over the email if wanted in your custom handlers. You can still use submission.Send()
Multiple Emails
To really be useful in a production setting it would be good to send an email to both the admin and the user. This update adds just that.
Config.Set
has been replaces with Forms.Add
. You provide the name of the form and a list of emails to be sent. The name of the form is now case sensitive but this may change in the future.
forms.Add("name", formailer.Email{}, formailer.Email{})
To allow separate SMTP settings for each email there is now an ID
field in Email
. It's used as a replacement to Name
.
Email{
ID: "emailID",
...
}
Redirects are now exclusively managed by the handler.
Moved Handlers & Google reCaptcha support
The Netlify and Vercel handlers have been moved into a new Handler package.
The faxonly
honey pot has been remove in favor of Google reCaptcha support. Add a RECAPTCHA_SECRET
to your env
with your captcha secret key.
I've only tested with v3 and the automatic bind method. This needs more testing.