An AWS Lambda function for processing HTML forms without the need to write backend code. This works by generating an email report for each form submission based off of the form field names and user submitted values.
- Run
npm installto pull in the required node packages. - Form-less uses the Serverless framework to simplify the AWS deployment process. To setup Serverless with your AWS account, follow the steps from their tutorial (note that the Serverless module is already added in the provided
package.jsonfile).
- Before deploying to AWS using Serverless, configurations values need to be added in
servereless.ymlfor the form handler. These configuration options are:- ALLOW_ALL_DOMAINS: Specifies whether or not all domains can POST forms to the form handler. Must be set to
"yes"or"no". - ALLOWED_DOMAINS: Specifies specific domains that can POST forms to the form handler. Is only considered if ALLOW_ALL_DOMAINS is set to
"no". Multiple domain names can be added by separating them with a comma (eg,"https://domain1.com/, https://domain2.com/") - Mailgun Fields: Form-less supports sending submission emails using the Mailgun email service. To enable Mailgun, set
MAILGUN_API_KEYto an API key for the Mailgun service,MAILGUN_FROM_EMAILto the address the submission emails should appear to come from, andMAILGUN_DOMAINto the domain you have connected to Mailgun. - SMTP Fields: As as alternative to Mailgun, Form-less also supports sending submission emails over SMTP (email account must support TLS). To use this method, set
SMTP_SERVERto the address for an SMTP email server,SMTP_EMAILto an email address on the SMTP server,SMTP_USERto the user associated with the email address (often the same as the email address),SMTP_PASSWORDto the password associated with the email address, andSMTP_PORTto the correct port for sending SMTP mail through the server (this port must support TLS).
- ALLOW_ALL_DOMAINS: Specifies whether or not all domains can POST forms to the form handler. Must be set to
- Once the configuration values are set, the Lambda function can now be deployed to AWS with the
serverless --deploycommand. Running this command will output an endpoint URL that will be needed during form setup below.
-
Once the Lambda function has been deployed, it can now be used in an HTML form. For the form to be processed correctly, the following format should be used:
- The
actionattribute for the form should be set to the endpoint output from theserverless --deploycommand, and themethodattribute should be set toPOST. - The form should have a hidden field named
_emailthat specifies the email address to send form submissions. - The form should have a hidden field named
_redirectthat specifies a URL to redirect the user to after the form is submitted. - The form can optionally have a hidden field named
_formnamethat (if provided) will be used to identify the form in the submission email. - The
nameattributes for each form field will be used to identify them in the submission email, so it is advisable to give fields a descriptive name. - If there is a field with the
nameattribute set toEmail, the value entered by the user into this field will be used as the reply-to address for the submission email.
- The
-
Example of a simple contact form:
<form action="[LAMBDA_ENDPOINT_GOES_HERE]" method="POST">
<input type="hidden" name="_redirect" value="https://example.com/contact-success-page">
<input type="hidden" name="_email" value="formsubmissionreceiver@example.com">
<input type="hidden" name="_formname" value="Example.com Contact Form">
<label for="Name">Name</label>
<input type="text" name="Name" required>
<label for="Email">Email</label>
<input type="email" name="Email" required>
<label for="Subject">Subject</label>
<input type="text" name="Subject" required>
<label for="Message">Message</label>
<textarea name="Message" rows="2" required></textarea>
<input type="submit">
</form>
- Most use cases for Form-less will likely fall under the AWS Lambda Free Tier due to the small amount of compute power needed to process form submissions. However, it is a good idea to monitor usage so that unexpected charges do not incur.
