We’ve made it very simple to create a form on your web site where new subscribers can sign up to your list (we provide the code, you just have to copy and paste). But what about when you’ve already got a form, and you simply want to add a checkbox where customers can opt-in to your newsletter? This isn’t quite a copy and paste job, but it’s not far off.
Lets take a look at a simple example. Your client’s site has a ‘Contact Us’ form, which sends an email to your client with the details of a customer enquiry. They’ve just decided that they want to add a little ‘Subscribe to our newsletter’ checkbox. How are you going to integrate this with Campaign Monitor? Here’s a few ways:
1. Use an extension or plugin
This is the simplest of all if you happen to be using a suitable CMS or shopping cart. We’ve got a bunch of downloadable plugins, extensions and modules for systems like Expression Engine, Joomla and FoxyCart.
Over on the right of this page you’ll see direct links to some of them. Check there first because it may be someone has already done the hard work for you.
2. Using the API
Lots of you already know about (and use) the API, and this is the obvious way you can achieve this. In our example, when a user submits the contact form on your clients web site, your already going to have some code in place to gather the contents of the form, and send them off to your client in an email (usually in something like PHP, ASP.NET, Perl etc). We just need to make a slight addition to this.
Using your programming language of choice you can check to see if the user has checked the ‘Subscribe to our newsletter’ checkbox, and if they have, make a call to our API to save this person to your subscriber list. And don’t worry if they’re already in there – we won’t add them twice.
3. Redirecting to specific URL’s
If your not too keen on the idea of calling our API, there’s another method you can use, which works by redirecting to a URL on our server which will save the user to the list, then send them back to your server.
So just like before, you gather the contents of your form, and send the email to your client. Now, to get the users name and email address into Campaign Monitor, we need to redirect the user to a specific URL.
What this redirect stuff you keep mentioning?
All server side languages should have an easy way to send the user to another URL. In PHP you would use something like:
header( "Location: hhttp://www.urlhere.com" );
and in ASP.NET it would look like
So let’s get down to specifics. The URL that we need to send the user to, is the same URL that we use in the Create a Subscribe Form code. Check out this code and you’ll see something like:
<form action="http://myclient.thisapp.com/p/a/t/tos/" method="post">.
The action URL is what we’re after, so in this case
We’re almost done, but when we redirect the user to the URL we need to include their email address (and optional name). We do this by adding them to the URL in a format like this:
So the full code in PHP would be
header( "Location: http://myclient.thisapp.com/p/a/t/tos/.
The important points to note are the question mark (?) to show the start of the variables, the ampersand (&) to separate the values we’re passing in, and the plus sign (+) which should be used to replace any spaces in the name.
Of course, you’ll need to grab the name and address values from your existing form, and plug those in where we have email@example.com for example.
When the user is redirected to the above URL, they will be added to your list, but what happens next? Well, hopefully you’ve added a custom subscribe page (and if you haven’t, just jump into the “Create a Subscribe Form” options in your list and add one), and the user will be redirected back to the subscribe confirmation page you’ve specified.
The best part is, both of these approaches happen so quickly the user won’t notice a thing.