Giter Site home page Giter Site logo

superstatic-forms's Introduction

Superstatic Forms

A simple service for capturing submitted forms via email.

NPM Module Build Status

Client Configuration

Superstatic Forms is configured by providing a JSON object with keys named for a specific form and values as described below. For example, your superstatic.json might have a section like this:

{
  "forms": {
    "contact": {
      "to": "[email protected]",
      "from": "[email protected]",
      "replyTo": "{{name}} <{{email}}>",
      "subject": "Contact Received from {{name}}",
      "html": "<b>Name:</b> {{name}}",
      "text": "Name: {{name}}",
      "success": "/contact-received",
      "failure": "/contact-failure"
    },
    "beta": {
      "to": "[email protected]",
      "from": "[email protected]",
      "subject": "Beta Signup",
      "text": "{{username}} ({{email}}) signed up for the private beta."
    }
  }
}

This would allow a form with method POST and action /__/forms/contact to submit a contact email, and action /__/forms/beta to submit a beta signup email. For example:

<form method="POST" action="/__/forms/contact">
  <label>Name:</label> <input type="text" name="name">
  <label>Email:</label> <input type="email" name="email">
  <button type="submit">Contact Us</button>
</form>

Configuration Options

  • to: (required) Email address of the recipient with optional name. This field cannot be dynamic.
  • from: (required) Email address to mark the email as being sent from.
  • replyTo: (optional) Reply-to address for easy follow-up.
  • subject: (required) Subject of the email.
  • html: (optional) HTML template for the email body.
  • text: (optional) Plain text template for the email body.
  • success: (required only if it's not an ajax request) Redirect URL on successful submission.
  • failure: (required only if it's not an ajax request) Redirect URL on failure.

The subject, replyTo, html, and text fields are all rendered using a Handlebars-like interpolation.

Note: To prevent spam and other abuse, the to address is only configurable in superstatic.json. It is not templatable.

Server-Side

You must provide server-side global configuration so that Superstatic Forms is able to send email. This service uses nodemailer in the background, so configuration is based on that.

require('superstatic-forms')({
  from: "[email protected]",
  transport: require('nodemailer-sendgrid-transport')({
    auth: {
      api_user: 'MY_USERNAME',
      api_key: 'MY_PASSWORD'
    }
  });
});

Note: As of superstatic-forms 0.4.0, nodemailer 1.0 is used and the transport should be passed in as a object, not a string with options.

superstatic-forms's People

Contributors

fastdivision avatar mbleigh avatar scottcorgan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.