Advanced Subscription Form Integration

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 Mautive URL and API Key. Example below:

define("Mautive_URL", "http://localhost/onsite");
define("Mautive_API_KEY", "a879fb51e...6f28123facc1d398");

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

require_once("../../Mautive-api-php/includes/Mautive.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!

  • 0 משתמשים שמצאו מאמר זה מועיל
?האם התשובה שקיבלתם הייתה מועילה

מאמרים קשורים

Detecting API Errors

Although you’ve carefully crafted your Mautive application to flow smoothly, it’s hard to...

Introducing ERJA. Get to know your subscribers like never before…

ERJA is an exclusive subscriber data feature that Mautive is releasing as an add-on to...

Use Marketing Automation to Gather and Improve Your Net Promoter Score℠

Rather than looking back at what happened, a Net Promoter Score ℠ (NPS®) is touted to be a...

Tutoriales de Mautive

Introducción Primeros Pasos Manejo de Contactos Formularios e Integraciones Campañas...

Social Sharing Updates

A couple quick updates regarding social sharing: Link only You can now (additionally) obtain...