Sign-upness

The other day my pal Sam asked me how I managed the Fever notification sign-up page. He wanted to do something similar for a new project he’s working on. So I sent Sam my source code and we decided that others might benefit from this simple solution.

Fever

The States

My sign-up pages usually have three states:

  1. The sign-up form
  2. The status message for subscribers
  3. The unsubscribe message for the dearly departed

All three states are served from the same page. Which state is displayed depends on an optional query string and the presence of a cookie.

The Workhorse

I’ve been using Campaign Monitor ever since Mint’s user base outgrew PHP’s native mail() function. It’s a great service, reliable, easy to use and reasonably priced.

Campaign Monitor provides a simple HTML form that you can copy/paste into your code and allows you to specify urls for custom subscribe and unsubscribe confirmation pages—which conveniently covers all three states. There’s even a Campaign Monitor Subscribers Pepper (created by Mark J. Reeves), which is handy if you’re Minted.

When you grab your form HTML from Campaign Monitor, set your subscribe confirmation page to the url of your sign-up page plus ?subscribed and your unsubscribe confirmation page to the url plus ?unsubscribe (no d).

The Glue

Copy the sample PHP file below, fill with your own wit and beauty (taking care not to disturb the cookie setting and PHP conditionals) and get back to work on that not-so-secret-anymore project we’re all dying to learn more about.

<?php

if (isset($_GET['subscribed']))
{
    setcookie('subscribed', 1, time() +  60 * 60 * 24 * 365);
}
else if (isset($_GET['unsubscribe']))
{
    setcookie('subscribed', '', time() -  60 * 60 * 24 * 365);
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><!-- TITLE --></title>
<!-- STYLESHEETS, JAVASCRIPT, MINT! -->
</head>
<body>

<!-- HEADER, ETC. -->

<?php if (isset($_GET['unsubscribe'])): ?>

    <!-- UNSUBSCRIBE MESSAGE HERE -->

<?php elseif (isset($_GET['subscribed']) || isset($_COOKIE['subscribed'])):?>

    <!-- STATUS MESSAGE FOR SUBSCRIBERS -->

<?php else:?>

    <!-- SIGN-UP FORM COPY/PASTED FROM CAMPAIGN MONITOR -->

<?php endif;?>

<!-- FOOTER, ETC. -->

</body>
</html>
Previous
An Event Apart San Francisco 2008
Next
LeRoi Moore 1961-2008
Author
Shaun Inman
Posted
August 19th, 2008 at 11:33 pm
Categories
PHP