Its a modular, open source tool that generates serverless web forms (front-end and back-end) in seconds. It leverages [CloudFormation](https://aws.amazon.com/cloudformation/) templates to create all of your necessary resources in the AWS cloud including a A Dynamo DB table, an API Gateway endpoint, and a lambda function. It also automatically generates a ready-to-go html contact form that you can copy-paste into your site. the tool is fast, easy to use/integrate, and completely free as all the AWS resources created have a free tier. Version 2 now features increased usability, security, and flexibility.
In the last couple of years the introduction of new cloud services for storage, compute, and content delivery have been improving the usability of static websites. These services allow us to build tools which can bypass most of the limitations commonly associated with static websites. One such limitation is adding forms that can process submissions. We built Super Easy Forms because we needed a fast, modular, open source solution to add/update contact forms in all of our static websites. We hope you find it useful.
mkdir project-name
replacing project-name with the desired name for your projectcd project-name
npm install super-easy-forms
npm install -g super-easy-forms-cli
$ sef build -r=your-aws-region -p=profile-name
from the root of your project's directory. replace profile-name with the desired name of the IAM user and your-aws-region with the desired AWS region code.~/.aws/credentials
in mac/linux or in C:\Users\USER_NAME\.aws\credentials
in windows. you can create/edit this file by runing sudo nano ~/.aws/credentials
. add the profile keys in the format shown bellow. [profilename]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
cd your-project-name
sef init formname
replace formname with the name you want to give to your new form. For example the domain name followed by paymentform../forms/formname/config.json
and add values for the variables shown bellow following the same format. captcha, emailMessage and emailSubject are optional. sef fullform formname
{
"email":"your@email.com",
"recipients":["recipient1@email.com","recipient2@email.com"],
"formFields":{
"fullName":{
"type":"text",
"label":"Full Name",
"required":true
},
"email":{
"type":"email",
"label":"Email",
"required":false
},
"payment":{
"type":"select",
"label":"Payment",
"required":true,
"options":{
"visa":"Visa",
"master_card":"Master card",
"cash":"Cash"
}
},
"paymentAmount":{
"type":"number",
"label":"Payment Amount",
"required":true
}
},
"captcha":false,
"emailSubject":"",
"emailMessage":"",
}
This creates the back-end and fornt-end for a form called formname. the form will have the fields Full Name, Email,Payment method (with options Visa, Master Card, or Cash) and payment amount. Whenever someone submits the form an email will be sent from your@email.com to recipient1@email.com and recipient2@email.com.
Optionally you can provide your desired values directly in the CLI flags without having to edit the config file as shown in the command bellow.
sef fullform formname --email=your@email.com --fields=fullName=text=required,email=email=required,paymentMethod=select=required=visa/master_card/cash,paymentAmount=number=required --recipients=recipient1@email.com,recipient2@email.com
const SEF = require('super-easy-forms')
SEF.CreateForm(formName, options, function(err, data){
if(err) console.error(err)
else{
//Do Something
}
})
All forms will generate a folder for that form within your project. this folder will contain the forms config.json file which keeps track of all of that form’s variables.
All of the super easy form commands make use of optional arguments and optional callbacks. if a required argument isn’t supplied to one of the methods that method will check the form's local config file and use the value stored there. if the argument isn't provided in params and isn't found in the form’s config file it will throw an error.
All methods have the function(formName, options, callback)
format and all the callbacks have the function(err,data)
format.
If a callback isn’t provided methods will return the data value or throw an error in the case of an error. If you don’t provide any options you can provide the callback as the second argument.
At the root of the project you will find the forms folder which will contain all of your forms
|- forms/
|- yourFrom/
|- exports/
|- yourForm.html
|- config.json
|- template.json
|- yourFormFunction.zip
|- yourFormFunction
|-index.js
|node_modules/
|- .env
|- .gitignore
|- settings.json
|- node_modules
|- super_easy_forms/
## Form Config fileA config.json file with all of the form variables is created for each of your forms.
{
"email":"String",
"emailSubject":"String",
"emailMessage":"String",
"recipients":[Array],
"formFields":{Object},
"endPointUrl":"String",
"captcha":true|false,
"zip": true|false,
"functionBucket": true|false,
"stackId":"String",
"restApiId":"String"
}
The CreateLambda method generates the node.js code for the lambda function and places it in a directory with its reuqired modules. Then it zips the directory and uploads it to an S3 bucket.
AWS CloudFormation is a IaC (Infrastructure as code) service from AWS that allows you to define stacks composed of AWS resources in a JSON or YAML file called a cloudformation template. This makes it easy to keep track of the multiple resources used by each of your forms. The cloudformation template is stored in each form’s directory in the file called template.json.
The createForm function takes in a JSON object with the format shown bellow and outputs a responsive HTML form (bootstrap) with an inline JQuery handler. In the config file, you can add labels/placeholders and provide options for things like required fields, different html types and more. The HTML form is completely customizable as its pure HTML; no iframes!
"formFields":{
"fullName":{
"type":"text",
"label":"Full Name",
"required":true
},
"email":{
"type":"email",
"label":"Email",
"required":false
},
"payment":{
"type":"select",
"label":"Payment",
"required":true,
"options":{
"visa":"Visa",
"master_card":"Master card",
"cash":"Cash"
}
},
"paymentAmount":{
"type":"number",
"label":"Payment Amount",
"required":true
}
},
The form and fullform commands in the CLI use the parseFields method which takes in a string in the following format --fields=fullName=text=required,email=email=required,paymentMethod=select=required=visa/master_card/cash,paymentAmount=number=required
and converts it to a JSON object with the required format be stored in the forms config file and passed to the createForm function. The labels option in the CLI adds human friendly labels to form inputs and to the select options by separating camel-cased characters, replacing underscores and dashes with spaces, and capitalizing first letters.SES is a service from AWS that allows you to send emails programmatically using any email provider. Please be aware that if you want to use AWS SES to send emails to external recipients (whose email addresses haven't been verified with SES in your AWS account) you must move out of the AWS SES Sandbox.
To verify a new email with AWS SES run sef email formName your@email.com -n
replacing formName with the name of your form and your@email with the email you want to verify.
Super easy forms allows you to easily integrate google's reCAPTCHA service into your html forms. Before being able to use this feature make sure to sign up for a reCAPTCHA key pair
Once you have added a key pair for the correct domain of your respective project, add the following variables in your .env file by running sudo nano .env
or opening the file in your text editor of choice.
RECAPTCHA_KEY=your_site_key
RECAPTCHA_SECRET=your_site_secret_key
now when you run a command from the CLI make sure to add the —recaptcha flag or -r shortcut. If you are using the API provide the captcha argument of the options param as true. If you are adding CAPTCHA to an already deployed form, make sure to also update your lambda function.
Please be aware that the captcha checkbox will not work unless the request is coming in from the domain you registered when requesting your key pair.
<FormOutput>
variable to include the output of the form in the message. The default message is: <h4>New Contact</h4><br><p>Someone has just filled out your super easy form! bellow are their details: <br> <FormOutput>
Super Easy Forms - New Contact
forms/formname/formnameFunction.zip
. Default value is false.name=type=required
. by default required is set to false and type to text. each form field must be sepparrated by comas. options in the slect field must be sepparated by /
Success
Success
Created a config file with no values for your form
Succesfully updated the lambda function
Builds the required base files and directories.
USAGE
$ sef build
OPTIONS
-p, --profile=profile The name of the iam profile/user that you want to create
-r, --region=region The desired AWS region were your forms infrastructure will be deployed
_See code: src/commands/build.js_Deletes all resources in the AWS cloud for the desired form
USAGE
$ sef delete NAME
ARGUMENTS
NAME name of the form you want to delete
OPTIONS
-r, --resources Delete all of the back-end resources for your form in the cloud
_See code: src/commands/delete.js_Deploys your stack in the AWS Cloud
USAGE
$ sef deploy NAME
ARGUMENTS
NAME name of the form you want to delete
OPTIONS
-c, --create Deploy a new cloudformation stack in the AWS cloud
-u, --update Update your stack in the AWS cloud
_See code: src/commands/deploy.js_Verifies/validates your email with AWS SES
USAGE
$ sef email EMAIL [NAME]
ARGUMENTS
EMAIL the email address that will send the form submission emails
NAME name of the form - must be unique
OPTIONS
-n, --new verifies a new email address to be used by AWS SES to send email
-v, --validate validates that the provided email address was verified with AWS SES
_See code: src/commands/email.js_Builds an html form
USAGE
$ sef form NAME
ARGUMENTS
NAME name of the form - must be unique
OPTIONS
-c, --captcha Adds recaptcha elements and scripts to the form
-f, --fields=fields Desired form formFields
-l, --labels Automatically add labels to your form
-u, --url=url The API endpoint endpointUrl for your form
_See code: src/commands/form.js_Generates an html form and saves it in the formNames folder
USAGE
$ sef fullform NAME
ARGUMENTS
NAME name of the form - must be unique
OPTIONS
-c, --captcha Adds recaptcha elements and scripts to the form and lambda function
-e, --email=email Email address that will be used to send emails
-f, --fields=fields Desired form formFields
-m, --message=message the email message body. you can use html and you can use <FormOutput> to include the
information from the form submission
-r, --recipients=recipients Recipients that will recieve emails on your behalf.
-s, --subject the subject of the email message
_See code: src/commands/fullform.js_display help for sef
USAGE
$ sef help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
_See code: @oclif/plugin-help_the --create flag will open up a window with the AWS console so that you confirm the creation of a user with the entered name.
USAGE
$ sef iam USER [REGION]
ARGUMENTS
USER name of the IAM user
REGION your desired AWS region.
OPTIONS
-c, --create Helps you create an IAM user and adds its profile to the .env file
_See code: src/commands/iam.js_Creates a config file with empty values for your form.
USAGE
$ sef init NAME
ARGUMENTS
NAME name of the form - must be unique
_See code: src/commands/init.js_Generates a lambda function and saves it as lambdaFunction.js in the formNames folder
USAGE
$ sef lambda NAME [ACTION]
ARGUMENTS
NAME name of the form - must be unique
ACTION (create|update) [default: create] action to perform to the lambda function - create or update
OPTIONS
-b, --bucket creates a new s3 bucket and uploads the zipped lambda function
-c, --captcha Adds recaptcha elements to the lambda function
-e, --email=email Email address that will be used to send emails
-f, --fields=fields Desired form formFields
-m, --message=message the email message body. you can use html and you can use <FormOutput> to include the
information from the form submission
-r, --recipients=recipients Recipients that will recieve emails on your behalf.
-s, --subject the subject of the email message
-z, --zip zips the lambda function
_See code: src/commands/lambda.js_export or list all of the suibmissions you have had to date for a selected form
USAGE
$ sef submissions NAME
ARGUMENTS
NAME name of the form
OPTIONS
-e, --export Exports all submissions for the form to its folder
-f, --format=csv|json Desired format csv|json
-l, --list print all submissions for the form to stdout
_See code: src/commands/submissions.js_validate/create/update your cloudformation template saved locally
USAGE
$ sef template NAME
ARGUMENTS
NAME name of the form - must be unique
OPTIONS
-c, --create Create a new cloudformation temmplate and saves it locally
-e, --email=email Email address that will be used to send emails
-f, --fields=fields Desired form formFields
-v, --validate Validate your cloudformation template with AWS
_See code: src/commands/template.js_Builds an html form
USAGE
$ sef variable NAME VARIABLE VALUE
ARGUMENTS
NAME name of the form
VARIABLE name of the variable
VALUE value of the variable
_See code: src/commands/variable.js_If you have modified the super-easy-forms source code and your commands are failing for some reason, you can run the test suite with npm test
. If this doesnt help you locate your errors youll have to debug your code.
If your forms arent being submitted you can these steps to troubleshoot:
sef template NAME -v
.curl -d '{"id":"", "fullName":"john doe", "email":"johndoe@email.com", "message":"hello world"}' -H 'Content-Type: application/json' https://your-api-url