Tip: Adding a MailBuild opt-in checkbox to an existing form
Posted by David Greiner on December 15, 2006 12:06 PM
Integrating a subscribe mechanism into an existing form for yourself or a client is a great way to attract new subscribers. For example, you might want to let people join your newsletter when they complete your contact form, or purchase something from a client's web site.
By following a few simple steps, you can easily add an opt-in checkbox to any form and hook it directly into your MailBuild list. For the advanced users out there that this is a no-brainer for, I'd recommend using the API. For the rest of us who don't do a lot of server-side work, there's another approach we can take using some simple redirects.
For this example, let's say you have a contact form on your client's site, like the following:

Now, let's jazz it up with an unchecked opt-in to join this client's monthly email newsletter list.

Now that the form has an opt-in option available, we need make a few changes to what happens after the form is submitted.
Get the address you should be redirecting to
Head into the subscriber list you'd like to integrate into this form in your account and click on "Add a subscribe form to my site". In the supplied HTML code, you'll notice a URL for the action= address like
http://clientname.createsenddotcom/t/1/s/d/. Copy that address.Modify your existing form code
Normally when you process a form, you'll redirect the user to a confirmation or thank-you page after all the processing is done (like generating an email for our example). 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.
Add the new subscriber's email address and name (optional) to the address of the page we're redirecting to
The first thing we need to do is grab the corresponding element name from our form for email address. So, if our email input is
<input type="text" name="mb-d-d" id="mb-d-d" />, it's themb-d-dthat we're after.Next, we add these values to the redirect URL by adding a question mark (?) followed by
mb-d-d=their email address&mb-name=their name.The full address should look something like:
http://clientname.createsenddotcom/t/1/s/d/?mb-d-d=name@domain.com&mb-name=Ben+RichardsonSet a subscribe confirmation page in your MailBuild account
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 the "Add a subscribe form to my site" we copied the address from. This will ensure they'll be silently redirected back to your own confirmation page after the subscriber is added to this client's list.
One last important thing to note is that these redirects will happen extremely fast and be transparent to your subscribers.
15 comments so far
Stay in the loop
Prefer updates via email? Sign up below and we'll send you all the good bits each month.
Dig into a category
- Articles/Tips
- Customer Template Gallery
- Happy Customers/Press
- Interviews & Case Studies
- New Features & Updates
- Observations & Answers
Search all posts
Free Email Templates
To get you started, we've put together dozens of free email templates that look great in all the major email clients.

jgil
wrote on January 17, 2007 1:19 AM
That´s a usefull tip but unfortunatly it´s a little hard for a non-programmer to implement, even without the API. To be straight:
Step 1: ok;
Step 2: ok, but what if they dont chech?
Step 3: Which form? It´s is really that hard or is it just "name" and "email"? The full address will look like your exemple but is that for "humans" do see? What´s the point?
Step 4: "We can now redirect ..." in wich form? Our´s or MailBuild´s?
Thanks!
Mic
wrote on February 2, 2007 1:49 AM
Hi guys, I've got an existing form that uses a simple formmail script (formmail.dreamhost.com) on my contact page to send me emails and it has the option of a redirect URL as a hidden field. Any ideas on how I can add the name and email address to the hidden field?
jenoe
wrote on February 2, 2007 2:13 AM
Hi guys,
I'm trying really hard to make it work (without the api that is).
I do not understand what we should put, at step 3, instead of domain@name.com and Ben+Richardson.
If I do put those, Ben Richardson does indeed add itself in my database. But any other try won't work.
Anything to add that I didn't think of?
Jason Hickey
wrote on February 2, 2007 11:33 AM
Hi Jenoe,
From what I understand, you have actually done the hard part, and are posting to the correct URL for your list. The remaining part is replacing the place holders in this example (name@domain.com and Ben+Richardson) with actual values from your form. If you are not trying log a name, just leave the &mb-name part out.
So say if you are using PHP, in the code section where you are redirecting to this address, access your form variables using something like $_POST['email'], or if you are using .NET, something like Request.Form["email"].
I'll also reply to your support request, so if I'm way off the mark on what you're doing, we'll take it up there.
Warren Black
wrote on May 26, 2007 12:10 AM
Hi,
I've used this method successful on a previous site, but now I'm trying to use it again, with the addition of custom fields. Should this be possible? I've simply added the additional field names (as per the sign up form) to the querystring, with the values I want inserted. It doesn't seem to work.
I'm I doing something wrong, or am I wasting my time, as this won't work with custom fields?
Jason Hickey
wrote on May 28, 2007 10:52 AM
Hi Warren,
We haven't included this functionality with custom fields, so no, it won't work. We've done this due to the potentially large values and type of data that people may try to pass through in this manner.
So if you need to get custom field data in with your subscriptions, check out the API where we've added a new method that will allow you to add subscribers with their associated field data.
Seti
wrote on July 16, 2007 11:25 AM
Hi, let me first off say I'm very impressed by Mailbuild! Will be using it very soon on a client. It came highly recommended on a design forum I visit.
The above tip looks useful, but I'm afraid I'm stumped by Step 3 also! Not sure what to put in place of name@domain.com and Ben+Richardson in the redirect URL, in other words, how to get the values of the name and email inputs in to replace the placeholders.
I should say that I'm using the ubiquitous NMS Formmail.pl to process my forms.
So is this the bit where I should, erm, really know Perl? :-'
(As Formmail.pl is such a common form handler for us designers/non-coders, is there any way you could post up what we need to put in here to grab the values of those two inputs - if possible?)
Jason Hickey
wrote on July 17, 2007 6:36 PM
Hi Seti,
What you are suggesting is pretty much spot on. You'll need to modify the perl script to access the variables being posted by your form for the name and email address of the subscriber. These values should then be substituted or appended into the redirect url above, where the name entered replaces Ben+Richardson, and the email address likewise.
If you've then specified a confirmation page in the Manage Subscribers part of the app, after we add the subscriber to your list, we'll forward on from there.
If you need any clarification on this, feel free to shoot an email to support
Chris Martin
wrote on September 13, 2007 1:16 AM
Does anyone have an example of this?
Dave Greiner
wrote on September 13, 2007 9:11 AM
Chris, this is server side code, so there isn't a live example we could link to that you could check out. We don't have a version in the API docs right now, but it's certainly something well consider for the future.
Simon Burley
wrote on January 25, 2008 2:43 AM
Could someone paste the relevant (server side) code here?
Or, if not how about a link to a download of a zip file with an example of the code?
I hope so, this could make MailBuild EVEN BETTER and MORE popular! (if possible).
shealyswife
wrote on February 20, 2008 2:22 PM
how can i add a log in form where ppl will have to register before ordering anything? please help- army wife new to this and needs help to boost site to keep my husbands deployment off my mind so much and keep busy. :(
Nelly
wrote on March 27, 2008 3:55 PM
I tried this in my php script but I keep getting the following campaign monitor error:
"We apologize for the inconvenience but an error has occurred. Please try again later."
My form code for the email field looks like:
"/>
and for the check box:
Subscribe me.
Finally my php script does:
$email = $_REQUEST['email'] ;
if (isset($_REQUEST['subscribeme'])) {
//if checked box, then redirect to subscribe url with the email address.
header("Location: http://xxxxx.cmail1.com/s/xxxxx?email=$email");
exit;
}
else { // ....redirect to thankyou page}
Can anyone see what I'm doing wrong as I don't know my way around php very well. Thanks.
michelle
wrote on May 29, 2008 7:50 AM
what if we don't want to add this functionality to a form page, but instead opt to do something that is used frequently on the web like what you have at the bottom of the page??? Can you post the script for this please?
Leon
wrote on July 21, 2008 10:29 PM
It would be great to see some ajax worked into this - and maybe even turned into a plug-in for popular CMS's - ie, Wordpress etc.
Got anything to add?