Sitemap
Patrick Beeson

Patrick Beeson

Full-stack developer for @thevariablelab. Cyclist. Homebrewer. Lover of mountains big and small.

Press enter or click to view image in full size
FormKeep is forms for developers by the awesome folks at thoughtbot. It’s made better with webhooks.

FormKeep and webhooks: A love story

3 min readOct 29, 2014

Drag-and-drop web form generators such as Wufoo have been around since the dawn of Web 2.0.

And while they’ve offered budding Web workers a way to introduce common HTTP verbs — GET and POST — these devices have always been a clunky and limiting experience.

That’s why thoughtbot’s FormKeep web service is such a fascinating concept.

FormKeep is part of a growing array of services that fit into the “____ for developers” paradigm. Think MailGun or Twilio or other such products that offload specific services that are then made available programatically.

You don’t use FormKeep to build a form. Instead, it’s simply the mechanism to POST to while leaving you to use best practices to build your form as you see fit.

And like a good citizen of the post-Web 2.0 world, FormKeep offers webhooks for paid accounts.

My use of FormKeep, and their webhook service, was aimed at solving a basic data capture problem at work. We needed a way of easily integrating a one-field Web form (email capture) into an otherwise static website while also capturing said email addresses into a transportable data structure.

Oh, and folks submitting their email addresses should get an email back after submission, too.

Our steps:

  1. User enters their email address into a standard form field
  2. The user’s email address is captured by FormKeep (available via CSV export or API access)
  3. A tiny Flask app catches incoming submissions via a webhook and responds to the address with an email containing additional information.

Of course, we could have accomplished this in a myriad number of ways. But time was tight, and FormKeep offered a way to tackle this immediately. (And I like experimenting with and supporting awesome products!)

Get Patrick Beeson’s stories in your inbox

Join Medium for free to get updates from this writer.

After setting up our form in FormKeep, I initiated a monthly subscription — webhooks are only available for paid accounts — and set the URL to one I use for exposing my local development servers to the Web (for quick sharing or for web services requiring it).

Then, I set to writing a basic Flask app to make use of the webhook (views.py):

import os
import textwrap
from flask import Flask, request
from flask.ext.mail import Mail, Message
from . import app
app.config.from_object(os.environ[‘APP_SETTINGS’])mail = Mail(app)@app.route(‘/’)
def home():
return “Nothing to see here. Move along.”
@app.route(‘/receive_email’, methods=[‘POST’])
def email_submissions():
email = request.values.get(‘email’, None)
if email:
msg = Message(
body=textwrap.dedent(“””\
You are receiving this email because you submitted your email
address at someurl.com.\n
”””),
subject=’Thank You For Your Interest!’,
sender=’noreply@someurl.com’,
recipients=[email])
mail.send(msg)
else:
return b”OH NO”
return b”OK”

You’ll also want to have a basic run.py module to fire up the dev server:

from app import appapp.run(debug=True)

Call run.py, fire up ngrok to expose your dev server to the Internet, and send (or hurl if you will) a POST request with the “email” parameter and value to your “receive_email” URL to test the webhook.

You should get a 200 response and an email if everything worked as intended.

Of course, this is just a basic example of the possibilities that exist using the FormKeep + webhook combo; you could also do things like pass hidden field values to use one form with different email responses.

Thanks again to the folks at thoughtbot for creating FormKeep and making it so flexible.

I’ve posted the code used for the project on GitHub.

--

--

Patrick Beeson
Patrick Beeson

Written by Patrick Beeson

Full-stack developer for @thevariablelab. Cyclist. Homebrewer. Lover of mountains big and small.