Tip: Capturing subscribers from an existing form
Posted by Ben Richardson on March 10, 2006
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 couple of ways:
1. 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.
2. 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.
header( "Location: http://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.. The action URL is what we're after, so in this case
.com/.aspx/s/4841/" ....>http://myclient.. 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:
.com/.aspx/s/4841/?cm-4841-4841=benr@campaignmonitor.com&name=Ben+Richardson.
So the full code in PHP would beheader( "Location: http://myclient.. The important points to note are the question mark (?) to show the start of the variables, the ampersand (&) to seperate the values we're passing in, and the plus sign (+) which should be used to replace any spaces in the name.
.com/.aspx/s/4841/
?cm-4841-4841=benr@campaignmonitor.com&name=Ben+Richardson" );
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.
18 comments so far
Search all posts
Dig into a category
- Articles/Tips (104)
- Email Newsletter Design (121)
- Happy Customers/Press (91)
- In the Forums (10)
- Interviews & Case Studies (9)
- New Features & Updates (112)
- Observations & Answers (89)
Stay in the loop
Prefer updates via email? Sign up below and we'll send you all the good bits each month.
Popular articles
Why we need standards support in email
Read why standards in HTML email are so important, and what we're doing about it.
Email design guidelines
Learn how to design for images being turned off, preview panes and other useful tips.
CSS support in email in 2007
The CSS support of every popular email environment with recommendations to boot.
Image blocking in email
A roundup of how each of the popular email clients suppress images in HTML email.
Can I use flash in email?
We test flash support in all the popular email clients. The verdict - don't do it.
Email design gallery
Our email design gallery showcases more than 150 amazing email designs sent by our talented customers.
Brian
wrote on March 11, 2006 9:11 AM
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.
Dave Greiner
wrote on March 11, 2006 11:00 AM
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.
Dave Greiner
wrote on March 14, 2006 10:47 AM
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.
Gil
wrote on March 23, 2006 1:51 PM
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!
rick kirk
wrote on March 24, 2006 6:43 PM
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.
David Greiner
wrote on March 24, 2006 8:24 PM
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.
Luiis
wrote on September 13, 2006 7:14 PM
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 :(
Dave Greiner
wrote on September 13, 2006 9:23 PM
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.
Barry
wrote on October 14, 2006 6:29 AM
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.
Matt Williamson
wrote on October 19, 2006 11:43 AM
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!
Dave Greiner
wrote on October 19, 2006 5:19 PM
Hey Matt, thanks for the chat earlier. Well try and get that new article together for you and everyone else soon.
Liam
wrote on October 25, 2006 11:52 PM
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
A Maclean
wrote on December 1, 2006 1:17 AM
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
Ben Richardson
wrote on December 1, 2006 1:39 PM
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.
Mark Hirst
wrote on January 31, 2007 7:11 PM
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?
bilgisayar
wrote on July 26, 2007 10:54 PM
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?
Ketan Vakil
wrote on July 27, 2007 9:46 AM
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!
Dave Greiner
wrote on July 27, 2007 10:38 PM
Ketan, to give you the best chance of getting an answer, I'd recommend posing that in the API section of our forums.
Got anything to add?