Tip: Capturing subscribers from an existing form

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
Response.Redirect(“http://www.urlhere.com”).

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
http://myclient.thisapp.com/p/a/t/tos/.

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:
?cm-4841-4841=sample@test.com&cm-name=Joe+Bloggs.

So the full code in PHP would be
header( “Location: http://myclient.thisapp.com/p/a/t/tos/
?cm-4841-4841=sample@test.com&cm-name=Joe+Bloggs” );
.

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 sample@test.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.

Posted in:

20 Comments

  1. Using the second method (via GET) would the person be directed to the unsubscribe page (as you indicated) or to the subscribe / Initial Confirmation page on the account? It seems to make more sense to direct the user to the Initial Confirmation Page.

  2. That’s right Brian, as soon as we’ve added them to your list, we’ll redirect them straight to your confirmation page (which happens in milliseconds). If it’s a double opt-in list, we’ll send them to the initial confirmation page, plus send them a confirmation email with a link to click to confirm their subscription.

    Using these methods is just like the subscriber completing the standard subscribe forms we supply.

  3. Brian, my apologies, we accidentally said the unsubscribe page, when we meant the subscribe confirmation page. Thanks for pointing that out, the tip has been updated.

  4. Sorry, but this is little hard to non-PHP-programers. But is a very important issue.  We really need to add a ‘Subscribe to our newsletter’ checkbox in every form we have. But, please, explain again the “after We’re almost done” part. And, again, sorry. And thanks!

  5. Good Post Gil!

    This is something that would be VERY helpfull Dave.
    Please provide some cut-n-paste checkbox code, (or step by step guide) for us to add to our existing forms to sign people up to the list, like the heading on this page implies!

    thanks a lot.

  6. Campaign Monitor team member

    Hey guys, sorry if this wasn’t as clear as it should have been. I’d say that the best approach for Gil and Rick would be the second approach. Here’s a quick step by step:

    1. Get the address you should be redirecting to
    This is the action= address from your subscribe form for that list.

    2. Modify your existing subscribe form code
    Normally when you process a form, you’ll redirect the user to a confirmation or thank-you page. Add a check to make sure someone has checked your list opt-in checkbox. If they have, we want to redirect them to the address specified above instead of the usual thank-you page. Before we do that, there’s one last thing…

    3. Add the new subscriber’s email address and name (optional) to the address of the page we’re redirecting to.
    We do that by adding a question mark (?) and then email= their email address &name;= their name.

    The full address should look something like:
    http://myclient.ourdomain.com/.asp/s/4841/
    ?email=benr@campaignmonitor.com&name=Ben+Richardson”

    4. Set a subscribe confirmation page
    We can now redirect them back to the same old thank-you page that we always use, so just copy and paste that address into the “Subscribe Confirmation Page” for that list in “Create a Subscribe Form”.

    Unfortunately there just isn’t any “copy and paste” approach here, because this depends on your server side language and each is different.

    Please let me know if any of this is unclear.

  7. Hi,
    I have created a newsletter form with custom fields, but when I try to subscribe me I receive this error:
    “Invalid Email Address”

    I use ASP.NET 2.0, and the second method, the URL string is:
    http://myclient.yourdomain.com/.asp/s/4841/?l74295-74295=mail@mail.com&firstnamemyfirstname&lastname;=mylastname

    I have tried also:
    http://myclient.yourdomain.com/.asp/s/4841/?email=mail@mail.com&firstnamemyfirstname&lastname;=mylastname

    BUt doesn’t work :(

  8. H Luiis, if you’re still having problems, your best bet is to submit a support incident and we’ll look into it for you.

  9. Trying to successfully pass a hidden parameter from an email to a web-based page with a form, and DB query (already there and handled by Oracle).
    Is there a way to do this from MS Outlook? I keep getting a file name NULL but if I copy and paste the code in a raw HTML form/page, it works fine.

  10. I’d like to swap out my DIV instead of redirecting to a new page.  Is there a tutorial or article somewhere so I can figure this out?  I submitted a support request to mailbuild already and have not heard anything yet.

    Thanks!

  11. Hey Matt, thanks for the chat earlier. Well try and get that new article together for you and everyone else soon.

  12. Hi,

    I’m sorry in advance for not being too up on php scripts.

    I have an online form when submitted gives a message that states your submission was succesful(or whatever message you wish to convey) The online form details are e-mailed to the allocated e-mail address.

    All fine and good except for the “successful submission” message is on a white background with black text which clashes with the websites colours.

    My question is can I add a redirect code to my existing script so as I can redirect to my website page (with colours etc. as I wish) while allowing for the form to work as is?

    and where do I add this exact code in my existing script.

    Thanks & Regards,
    Liam

  13. Hi, my client has a classic asp site. They wish to use Campaign Monitor, Does any one have an example for classic asp. I had no issues getting the web service running with asp.net 2.0.. just after a simple option for classic now.

    Many thanks in advance

    A

  14. Campaign Monitor team member

    Hey A,

    Getting this working with classic ASP shouldn’t be a problem. There are a couple of techniques you could use, such as the redirect method discussed above, or via the API using SOAP - here’s an example of using SOAP with classic ASP.

    If your still having problems please contact support and we’ll be able to help you out.

  15. I need to do this too and am trying to decide which method to use. You seem to sugest that the API is the better solution but I cant figure out where I am to start using this method. Are there any instructions anywhere on how to achieve the above using API? API is completly new to me, does this mean I should consider the second method?

  16. Are there any instructions anywhere on how to achieve the above using API? API is completly new to me, does this mean I should consider the second method?

  17. Does anyone have an example of either the API or the redirect method working on an ASP server? Even with the redirect method, you still need to use some sort of ASP variable to hold all the data to use in the redirect string, correct?

    Thanks!

  18. Ketan, to give you the best chance of getting an answer, I’d recommend posing that in the API section of our forums.

  19. They wish to use Campaign Monitor, Does any one have an example for classic asp. I had no issues getting the web service running with asp.net 2.0…

  20. I have an online form when submitted gives a message that states your submission was succesful(or whatever message you wish to convey) The online form details are e-mailed to the allocated e-mail address.

Comments for this entry are closed.

Explore the Email Gallery

@herron_bird That’s totally awesome - thank you for checking out worldview! :D ^RH

Follow us on Twitter