ActiveCampaign Subscription Form API Script: Embed and customize your forms on any site.
- Our PHP API library
- jQuery (if using the Ajax option, or loading existing contact details)
You can install example-subscription_form_embed by downloading (or cloning) the source.
Input your ActiveCampaign URL and API Key. Example below:
define("ACTIVECAMPAIGN_URL", "YOUR ACTIVECAMPAIGN URL"); define("ACTIVECAMPAIGN_API_KEY", "YOUR ACTIVECAMPAIGN API KEY");
Make sure the path to the PHP library is correct:
require_once("../../activecampaign-api-php/includes/ActiveCampaign.class.php");
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
or1
. Whether or not the form submits via standard page reload, or Ajax (requires jQuery).css
:0
or1
. 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 (based on the email address). If you wish to simply perform an ADD (no edit), delete this portion of Form.class.php
:
To load an existing contact's details in your form (name, email, and custom field values), include the contact hash in the URL (IE: index.php?hash=ihfsaduh038d3q...
).
Learn more about syncing subscribers.
We'd love to help if you have questions or problems. Report issues using the Github Issue Tracker or email help@activecampaign.com.