Skip to content

Releases: torrayne/formailer

Update Username

24 May 22:50
Compare
Choose a tag to compare
Update Username Pre-release
Pre-release
  • Update github username

Upgrade Go

24 May 22:48
Compare
Choose a tag to compare
Upgrade Go Pre-release
Pre-release
  • Upgrade to Go 1.22

Fix custom configs

18 Oct 21:10
da90fbd
Compare
Choose a tag to compare
Fix custom configs Pre-release
Pre-release

What's Changed

New Contributors

Full Changelog: v0.5.3...v0.5.4

Update built-in handlers

25 Mar 17:03
2695e87
Compare
Choose a tag to compare
Pre-release
  • Add logging to built-in handlers
  • Change response type to JSON
  • Clarify some errors

More Polish

24 Mar 17:18
b6f8580
Compare
Choose a tag to compare
More Polish Pre-release
Pre-release

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

22 Mar 17:42
256472b
Compare
Choose a tag to compare
Recaptcha Fix Pre-release
Pre-release

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

19 Mar 05:37
Compare
Choose a tag to compare
QoL & Polish Pre-release
Pre-release

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 building Submission.Order. This is an easy way to prevent rendering certain fields when ranging over the submission's values. If Ignore is nil it defaults to _form_name and g-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

10 Mar 23:38
Compare
Choose a tag to compare
Pre-release

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

06 Mar 08:18
7a1a67e
Compare
Choose a tag to compare
Multiple Emails Pre-release
Pre-release

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

05 Mar 19:02
Compare
Choose a tag to compare

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.