- Build
- Features
Form Submissions
Send form submissions to Stackbit's API and receive an email notification with the form content.
Stackbit supports the ability to accept form submissions and send a summary of the form response content in an email notification.
The process works like this:
- Specify an email destination.
- Sign the email string with a secret key.
- Submit form response to a server-side function.
- Post response to Stackbit's API and return the result to the front end.
Specify & Sign Email Destination
The destination is the email address to which Stackbit will deliver the form response summary when a request is submitted.
Configurable Destination
The email destination can be content specified by editors and delivered from your content source, or it can be a hard-coded value that you provide directly.
Signing Email String
Once you have the destination (as a string), you must sign it using a STACKBIT_CONTACT_FORM_SECRET
environment variable. This value must be provided by Stackbit. Contact support@stackbit.com to request your secret value (you'll need to provide your project ID).
Prior to rendering your form, you must sign the email address. Do this on the server-side so as to not expose this key. We recommend using jose-jwt and crypto, like this:
1
2
3
4
5
6
7
Pass the destination
value to your form component. (Note that 'hello@example.com'
is the string representing the email that should be replaced with the appropriate value for your project.)
Form & Submission Structure
Your form can be structured however you'd like. The only requirement is that you pass a form-destination
key-value pair with the signed email destination.
1
Server-Side Function
Submit the form to some server-side function so that you don't expose Stackbit's submission endpoint. Here is an example of an AWS Lambda function using the axios library
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Notice here that you have another environment variable — STACKBIT_CONTACT_FORM_SUBMISSION_URL
. This must also be provided by Stackbit. Contact support@stackbit.com to request the value for your site (you'll need to provide your project ID).