Advanced Subscription Form Integration

NOTE: Our form builder has been updated since this was posted. Find information about our current form builder solution here and read the blog post announcement here

Subscription forms are key components for growing your subscriber lists through your web presence, so it’s important to have easy ways to embed (and customize) them on your websites and within other applications.

All subscription forms you create within the software can be quickly embedded onto your website by copying and pasting the HTML (and CSS) code. You can also embed a subscription form onto your Facebook Page in a few easy steps.

Screenshot of ActiveCampaign subscription form integration

We also have several integrations (with third-party software) that work with subscription sign-ups (either by providing forms, or capturing form data), including:

  • WordPress
  • Wufoo
  • Magento
  • Joomla
  • Unbounce

Advanced integration

If you are an advanced user looking for more flexibility, you can embed (and process) subscription forms using our API, which provides you complete control over the subscription form appearance and behavior.

This post will provide some examples using our PHP API library of embedding a subscription form onto your site, and controlling how it’s submitted (standard browser reload or Ajax), how it’s styled (include styles used when setting up the form, or remove all CSS), and what URL it posts data to. This allows you more flexibility on how your subscription form behaves on your site.

Requirements

  1. Our PHP API library
  2. jQuery (if using the Ajax option)
  3. Familiarity working with PHP code

Setup

First, obtain our sample script which will provide the code needed to interact with subscription forms through our API.

At the top of that file, input your ActiveCampaign URL and API Key. Example below:

define("ACTIVECAMPAIGN_URL", "http://localhost/onsite");
define("ACTIVECAMPAIGN_API_KEY", "a879fb51e...6f28123facc1d398");

Make sure the ActiveCampaign.class.php file include is referencing the correct relative path:

require_once("../../activecampaign-api-php/includes/ActiveCampaign.class.php");

Next, set up your subscription form embed parameters:

$form_embed_params = array(
  "id" => 1026,
  "action" => "",
  "ajax" => 1,
  "css" => 1,
);

Here is a breakdown of each:

  • id: The ID of your subscription form.
  • action: The URL that your subscription form will post data to (leave out this parameter completely if you want to post it to the default location, or set to empty string to post to the same page the script is running).
  • ajax: 0 or 1. Whether or not the form submits via standard page reload, or Ajax (requires jQuery).
  • css: 0 or 1. Whether or not to include (or remove) the default CSS that comes with each subscription form.

Finally, decide whether to perform a sync or standard add/edit:

// set to 1 to sync
$sync = 0;

A sync does not require a subscriber ID, and will automatically add or edit, depending if they exist already. Learn more.

Key code samples

Our sample script will handle everything for you (once you input the parameters and settings), but here are some more detailed examples of what’s actually happening in the script:

You can easily embed a subscription form anywhere on your site by using this example PHP code:

$form_html = $ac->api("form/embed?id=1026");
echo $form_html;

Change 1026 to your own subscription form ID.

To process the form request (if posted to the same page, where the action parameter is set to empty string):

$form_process = $ac->api("form/process");

Set “sync” to true (by default it’s false):

$form_process = $ac->api("form/process?sync=1");

To control how the form is submitted (standard page reload or Ajax), set the ajax parameter:

$form_html = $ac->api("form/embed?id=1026&ajax=1");

To remove the default CSS included with the form (sometimes it conflicts with your own site’s styles):

$form_html = $ac->api("form/embed?id=1026&css=0");

And to set your own post URL (so you can direct it to any page after submission):

$form_html = $ac->api("form/embed?id=1026&action=" . urlencode("http://mysite.com/process"));

Our sample script outputs the result message (or error) directly above the subscription form, but you can move this anywhere you want.

Screenshot of ActiveCampaign subscription form result

Please try out our sample script and let us know if you are having any trouble, or anything we can do to improve this!

A trial is worth a thousand words.
Get started today, no credit card required.

 
 
  • Pingback: Subscription Form integration using the API | ActiveCampaign Email Marketing Blog()

  • Nina Meiers

    Hello – thanks for a great product – how do I remove the footer – email marketing by active campaign. i have some premium clients I do not wish to have any branding with.

    • MattThommes

      Hi Nina,

      Have you tried turning off branding within the software (Design settings, Advanced Options, Hide product links)? That removes the footer within the form altogether.

      Let us know if that still does not work for you.

      Thanks!

  • Hi – you can add contacts using contact_sync API method, or users with user_add. What specific questions or issues are you having?

  • jvandeboom

    Yes, you can set a custom URL redirection if you go to the form settings and change the confirmation page.

  • That one at the bottom was created in ActiveCampaign. :) Your only other option is to remove the CSS from the form code, and style it yourself.

    • how do we do ones as nice as what is at the bottom of this page? I’m with Robert, the built in ones are rather old. I know you have new ones, but any hope of helping us get something close to what you have here

      • Brian Gladu

        Hi Patrick —

        The new form builder’s release is imminent. It’s coming out of beta testing and we’ll be announcing it here on the blog very, very soon (within days, not weeks).

        You’ll be able to create forms very similar to what appears at the bottom of our blog posts.

  • Mike Lewis

    The links to the sample script are broken

  • Julia Barrero

    Hey Matt,

    Is there any way to embed a form in an automated ActiveCampaign email? For example, if I’m sending drip campaign and want to know what business vertical a customer belongs to, can I create a form field that they can submit directly from within the email?

    Thanks!

    • Hi, for deliverability reasons, it’s not always best to embed forms into emails. It might render it partially, but the functionality may not work as intended. One suggestion is to create a button in the email that links to your form page (maybe the page just has the form on it) and use our personalization tags (in the button link URL) to pass the contact’s data into the form.

      Hope that helps!

  • I set up a form to manually add emails to that would trigger a follow up using the embeddable html form. It is not customer facing, just something I use as a utility. If I enter them too rapidly I start getting a captcha. Any way to turn this off? Any documentation on what rate triggers this?

    Thanks!

    Nate

    • Brian Gladu

      Hi Nate!

      The CAPTCHA is triggered by 3 submissions per minute or 10 submissions per hour and can’t be turned off without some kind of custom code.

      I can see how this would be inconvenient for that use and might suggest using an integration to place a form without this feature.

      • Thanks Brian, could you point me to a good one?

        • Brian Gladu

          I’m a big fan of Wufoo, but you could use Google Forms or something along those lines.

  • John

    These forms are so ugly… why are you trapped in 1999!!! Yikes…

  • Miko B

    Hi, I was wondering if we can redirect a user into custom pages/URLs depending on a select drop-down value they choose using this?

    I have followed the instructions here and the form is properly submitting data to my list: https://github.com/ActiveCampaign/example-subscription_form_embed

    So if they have selected the value 1 — they will be redirected on a custom URL
    The same with value 2 — they will be redirected to a different URL.

    Thank you in advance!