Skip to main content
Act-On Software

Integrating an Act-On Form External Post with WordPress

AUDIENCE: Web Developers, WordPress Administrators
OBJECTIVES: 

  • Integrate an Act-On form external post with the WordPress plug-in Contact Form 7 
  • Integrate an Act-On form external post with the WordPress plug-in Gravity Forms 
  • Integrate an Act-On form external post with the WordPress plug-in WP-Members
  • Provide guidelines for integration with Act-On when the above do not apply
WordPress is a freely available, open-source CMS that is highly popular and extensible. Many plugins exist to create webforms within WordPress, or WordPress developers can develop their own custom solutions. The External Posting article is written for all webpages, but those using WordPress may find the documentation within this article to suit their needs more closely.

AOmegaphonesmall.pngPlease note:

If you are hoping to add your beacon tracking code to WordPress, please instead see Integrating the Beacon Tracking Code into a WordPress Website. 

 Contact Form 7

Many website administrators use the WordPress plug-in Contact Form 7, which is a popular, free, and easy-to-use form-creation tool. This plug-in works by allowing the user to generate a form using the plug-in's interface, and then integrate the constructed form onto any WordPress page or post using a shortcode such as [contact-form-7 id="1" title="Contact form 1"].  Contact Form 7 utilizes PHP-based (server-side) validation, so it requires an adaptation of the standard methods referenced in the article Posting External Forms to Act-On.

The following are the steps required.

AOmegaphonesmall.pngPlease note:

Please make sure your Contact Form 7 Wordpress plugin is up to date!

Step 1:

For each form this is used with, we need an equivalent 'mirror' version of the form to be created within Act-On. For example, if a custom form on your website captures First Name, Last Name, and Email, you'll need to create a form within Act-On that also requests these fields. Your website visitors will never see this Act-On variant of your form -- we simply need to receive your custom form’s data.

Step 2:

Next, you'll want to make sure the input names match so that information can be passed properly. In the form builder, you'll see an Edit button appear when hovering over any form field. Click Edit, and take a look at 'Data Field Name' on the resulting pop-up menu. You want to ensure that your 'Data Field Name' matches your custom form's HTML input name.

For example, if your First Name field in Act-On has a Data Field Name of 'fname', you'll want your custom form HTML to contain '<input name='fname'... ' for the equivalent field.

If you make any changes, be sure to click Next twice in the Act-On form builder until you get to the last step, where you can save your form.

Step 3:

You'll want to copy your Act-On form's public URL. This is located under Content > Forms. Hover over your form and click the drop down arrow... > Get Public URL.

Step 4:

When you have your specific URL, you'll want to grab these elements from the form’s public URL to plug into the script below:

  • Your marketing subdomain, if applicable (such as yourcomapnyname.actonsoftware.com, or marketing.companyname.com if you use a custom URL for your account -- do not include 'http' or 'www' before the domain, or any characters after '.com' or '.org')
  • AccountId (Account ID) -- This will never change for your account
  • FID (Form ID) -- This will iterate for each unique form you have

Your form’s public URL will look like this. See the areas below in square brackets that contain the AID, FID, and DID:

http://marketing-domain/acton/form/[aid]/[fid]:[did]/0/index.htm

and then fill it into the script below in the first line, where you see "accountId", "formId", and "marketingDomain" at the very top of the script.

 

Step 5:

Take the parameters from the previous step's instructions and plug them into the variables at the very top of the script (accountId, formId, and marketingDomain). Now copy that script into your clipboard.

<script>var accountId = "account-id-here";var formId = "form-id-here";var marketingDomain = "marketing-url-without-the-http";</script>
<script type="text/javascript" src="//a11058.actonservice.com/cdnr/67/acton/attachment/11058/f-0083/1/-/-/-/-/WPCF7Script.js"></script>

 

Step 6:

In your Wordpress side bar, navigate to Contact >  Contact Forms and find the form you want to capture. Edit the form.

Screenshot_121117_092025_AM.jpg

Finally, paste the script below the other form elements (typically the final form element will be the "Submit" button).

Screenshot_121117_092241_AM.jpg

If you have more than one Contact Form 7 on a particular page, using the above process will result in submission of all forms on the page, leading to confused analytics. Please instead use the following process to target individual forms on the page continuing from step 5 on the previous process.

Step 6:

<script src="//a11058.actonservice.com/cdnr/67/acton/attachment/11058/f-008b/1/-/-/-/-/wpcf7byID.js"></script>
<script>document.querySelector("form[action*='form-id-here']").addEventListener('submit', function(event) {event.preventDefault(); var divId = document.querySelector("div[id*='form-id-here']").getAttribute("id");processwpcf7("account-id-here", "act-on-form-id", "marketing-url-without-http", divId, ""),false});</script>

 

In this script, you will be replacing "Account ID Here", "Act-On-Form-ID-Here", and "Marketing-Domain-Here" (highlighted) with the parameters you found in the previous steps. You will replace "Form-ID-here"  with the ID of the Contact Form 7.

These can be found by looking at the Contact Form 7 Shortcode. In the following example, the form IDs would be 71 and 75 respectively.

Screenshot_101217_024919_PM.jpg

NOTE: Please only include the top line of the multi-form script (<script src="//a11058.actonservice.com/cdnr/67/acton/attachment/11058/f-008b/1/-/-/-/-/wpcf7byID.js"></script>) once per page, on the first form. You may remove that line of the script when updating the code for other Contact Form 7s on the page.

Step 7:

Head to Contact > Contact Forms, find the form you want to integrate and click Edit.

Screenshot_121117_092025_AM.jpg

 

Now paste the script below the form elements (typically the final form element will be [submit "Send"]).

Screenshot_121117_093255_AM.jpg

 

AOmegaphonesmall.pngPlease note:

File uploads from Contact Form 7 can't be sent to Act-On via this process. If file uploading is essential, you will want to iframe your Act-On form.

 

Gravity Forms is a popular and easy-to-use WordPress plug-in for generating forms. It has a number of options and there are numerous possibilities for you to send data to Act-On. However, the following are the integration methods we recommend. All of these methods will properly update the cookie Act-On places on your visitors' browsers.

There are slightly different steps to follow, depending on whether you would like Gravity Forms to redirect to a new page upon form submission or if you are using a 'Thank You' message for your form (displayed on the same page as your form). The option you choose depends on where you would like to send your website visitors once they submit a form, and the corresponding steps described below are all equally reliable.

For either of the above options, we will be working with the Confirmations section of the Gravity Forms interface. To navigate here:

  • Log into your WordPress administrator page.
  • Click Forms in the sidebar to load the Gravity Forms setup interface.
  • Click the name of the form which you would like to integrate with Act-On.
  • Click Form Settings.
  • Click Confirmations.
  • Click Edit on Default Confirmation.

In this guide, you will see the following options for Confirmation Type listed below:

  • Text
  • Page
  • Redirect

Choose the option that best fits how you would like to process your Gravity Forms submission. This process is done on a per-form basis within the individual forms' settings, and does not apply globally to all your Gravity Forms.

Web developers: If you are comfortable modifying the WordPress functions.php file and doing a more advanced integration may want to see the Gravity Forms API-based integration section instead.

AOmegaphonesmall.pngPlease note:

File uploads from Gravity Forms can't be sent to Act-On via this process. If file uploading is essential, you will want to iframe your Act-On form.

Text

Text will display a message when the form is submitted (your form will disappear on the page, and the message will appear in its place), but will not redirect the form submitter to a new page. If you are using this option:

  • In Act-On, navigate to Content > Forms, and create a form with the fields you are hoping to capture and store in a list. Your website visitors will not see this form -- it exists as a 'proxy' used to receive data from Gravity Forms. Make note of the Data Field Name for each of your fields, as we will be feeding those Data Field Names into your Gravity Form.
  • In Act-On, navigate to Content > Form Post URLs. Generate an external post URL for the 'proxy form' you created in Step 1.
  • In the WordPress administrator interface, open up Gravity Forms and navigate to the Text confirmation behavior (steps to navigate there are described at the beginning of this article).
  • Paste in the following script:

<script>var externalPostURL="FORM-POST-URL-GOES-HERE";var queryString="QUERY-STRING-HERE";var aoIfrm=document.createElement("iframe");document.body.appendChild(aoIfrm);aoIfrm.setAttribute("id","ifrm");aoIfrm.style.backgroundColor="transparent";aoIfrm.style.border="none";aoIfrm.style.width="1px";aoIfrm.style.height="1px";aoIfrm.src=externalPostURL+"?"+queryString</script>
 

 

  • If you have any existing message present in this text box, paste the script below everything else.
  • Note that the above script does not contain any line breaks (the new lines you see above is your browser using word-wrap). When you paste this in, ensure that no hard line breaks are present because otherwise it will break the Gravity Forms script implementation.
  • Replace 'FORM-POST-URL-GOES-HERE' with your 'Form Post URL' you generated in Step 1, keeping the quotes
  • Replace 'QUERY-STRING-HERE' with your query string. 
  • To create the query string:
  • Click the drop-down icon next to the text box, and you will see a list of fields available to your Gravity Form
  • Click the field name in this list for each field you would like to add. For example, this will add something like the following for the default First Name field:

 


{Name (First):1.3}
 

 

  • With the above, this will pass the value of the submission. If I submit 'John', it will output 'John'. However, we also need to specify which input field this corresponds to. To do this, type in the name followed by an equals sign. The name you choose should match the corresponding data field in your Act-On proxy form.
  • If the name in Act-On has a space, you'll need to encode it. For example, a space (' ') is encoded as '%20' since we can't put a space in a URL.
  • Example that maps the value to 'First Name' (note the '%20' encoded space):

 


First%20Name={Name (First):1.3}
 

 

  • This will output 'First%20Name=John' in our example mentioned above.
  • Do the same for your other fields, but separate them with a '&'. For example, here is what capturing first/last name and email could look like (note the ampersand characters):

 


First%20Name={Name (First):1.3}&Last%20Name={Name (Last):1.6}&E-mail%20Address={Email:2}
 
  • Save your changes and test it. Your form submitters will now have their information sent to Act-On and they will be converted to known visitors. If you see in Act-On that you are getting blanks for some of your form fields, double-check your mapping between 'Data Field Name' and the query strings you set in Step 6.

 Standard Implementation: Page Method

Page

Page will send form submitters to an existing page that is part of your WordPress. If you are using this option:

  • In Act-On, navigate to Content > Forms, and create a form with the fields you would like to capture and store in a list. Your website visitors will not see this form -- it exists as a proxy used to receive data from Gravity Forms. Make note of the Data Field Name for each of your fields, as we will be feeding those Data Field Names into your Gravity Form.
  • In Act-On, navigate to Content > Form Post URLs. Generate an external post URL for the proxy form you created in Step 1.
  • In the WordPress administrator interface, open up Gravity Forms and navigate to the Page confirmation behavior (steps to navigate there are described at the beginning of this article).
  • Select the page on your WordPress site that you would like your form submitters to be sent to.
  • Check Pass Field Data Via Query String. This will expose a text area with a drop-down icon floating to the right of the text area. 
  • Click this icon, and you will see a list of fields available to your Gravity Form.
  • Click the field name in this list for each field you hope to add. For example, if you were to choose First Name it will add something like the following for the default First Name field:

{Name (First):1.3}
 
  • With the above, this will pass the value of the submission. If I submit 'John', it will output 'John'. However, we also need to specify which input field this corresponds to. To do this, enter the name followed by an equals sign. The name you choose should match the corresponding data field in your Act-On proxy form.
  • If the name in Act-On has a space, you'll need to encode it. For example, a space (' ') is encoded as '%20' since we can't put a space in a URL.
  • Example that maps the value to First Name (note the '%20' encoded space)

First%20Name={Name (First):1.3}
 
  • This will output 'First%20Name=John' in our example mentioned above.
  • Do the same for your other fields, but separate them with a '&'. For example, here is what capturing first/last name and email could look like (note the ampersand characters):

First%20Name={Name (First):1.3}&Last%20Name={Name (Last):1.6}&E-mail%20Address={Email:2}
 
  • On your WordPress page that form submitters will be sent to, paste in the following script anywhere on the page:

<script>
var aoExternalPostURL = "PROXY-URL-GOES-HERE";
window.onload = function () {
if (String(window.location).search("%40")>0) { 
var aoUrlParams;var aoQuery = window.location.search.substring(1);
(window.onpopstate = function () {var e, t = /([^&=]+)=?([^&]*)/g;
aoUrlParams = {};
while (e = t.exec(aoQuery)) aoUrlParams[encodeURIComponent(e[1])] = e[2]})();
for (i in aoUrlParams) {var aoUrlParamsArray = aoUrlParams[i];
try {document.getElementsByName(i)[0].value = decodeURIComponent(aoUrlParamsArray)} 
catch (err) {}
};
var aoIfrm = document.createElement("iframe");
document.body.appendChild(aoIfrm);
aoIfrm.setAttribute("id", "ifrm");
aoIfrm.style.backgroundColor = "transparent";
aoIfrm.style.border = "none";
aoIfrm.style.width = "1px";
aoIfrm.style.height = "1px";
aoIfrm.src = aoExternalPostURL + "?" + aoQuery;
};
};
</script>
 

 

  • Replace "PROXY-URL-GOES-HERE" at the top of your script with your proxy form URL (do not remove the quotation marks).
  • Save your changes, and test your form. It should now send form submitters to your response page, but now with their submission data passed through the query string in the URL. This will then be captured and sent to Act-On on the response page

Standard Implementation: Redirect Method

Redirect

Redirect lets you set any URL as the destination for visitors to be sent to, once they submit the form. If you are using this option:

  • In Act-On, navigate to Content > Forms, and create a form with the fields you are hoping to capture and store in a list. Your website visitors will not see this form -- it exists as a proxy used to receive data from Gravity Forms. Make note of the Data Field Name for each of your fields, as we will be feeding those Data Field Names into your Gravity Form.
  • In the form editor (in Act-On), click Next to navigate to Settings. Under the Response Page section, look for Redirect to URL and paste in the URL you want your form submitters to be sent to once they complete your Gravity Form.
  • In Act-On, navigate to Content > Form Post URLs. Generate an external post URL for the proxy form you created in Step 1.
  • In the WordPress administrator interface, open up Gravity Forms and navigate to the Redirect confirmation behavior (steps to navigate there are described at the beginning of this article).
  • In the Redirect URL input, paste in your Form Post URL that you generated in Step 1.
  • Check Pass Field Data Via Query String. This will expose a text area with a drop-down icon floating to the right of the text area. 
  • Click this icon, and you will see a list of fields available to your Gravity Form.
  • Click the field name in this list for each field you hope to add. For example, this will add something like the following for the default First Name field:

{Name (First):1.3}
 
  • With the above, this will pass the value of the submission. If I submit 'John', it will output 'John'. However, we also need to specify which input field this corresponds to. To do this, enter the name followed by an equals sign. The name you choose should match the corresponding data field in your Act-On proxy form.
  • If the name in Act-On has a space, you'll need to encode it. For example, a space (' ') is encoded as '%20' since we can't put a space in a URL.
  • Example that maps the value to 'First Name' (note the '%20' encoded space):

First%20Name={Name (First):1.3}
 
  • This will output 'First%20Name=John' in our example mentioned above.
  • Do the same for your other fields, but separate them with a '&'. For example, here is what capturing first/last name and email could look like (note the ampersand characters):

First%20Name={Name (First):1.3}&Last%20Name={Name (Last):1.6}&E-mail%20Address={Email:2}
 
  • Save your changes, and test your form. It should now send form submitters to your Act-On external post URL with their submission data passed through the query string. They will then be immediately redirected back to your own custom response page, allowing Act-On to capture data and convert your visitors to known with no visual interruption.

Standard Implementation: Frequently Asked Questions

Frequently Asked Questions

What is a query string?

By using web browsers, you have encountered a query string before. Here is a high-level overview of what a query string is:

  • Query string – A line (string) of text that is used to pass information. For our purposes here, this is always done inside a URL.
    • For instance, when you search Google, you will see that your search terms are present in the URL when you look at results. This is done via a query-string.
    • https://www.google.com/search?q=search+term is an example of this
      • https://www.google.com is the domain and is not the query string. The query string is q=search+term.
      • '?' indicates the start of the query string, and characters that can't go inside a URL such as a space are encoded or changed (' ' becomes '+').
  • Field – The first part of a query string
    • In q=search+term, 'q'is the field
    • The format is field=value
  • Value – The latter part of a query string
    • In q=search+term, 'search+term' is the value
    • If there are multiple fields and values, the format in a URL is: field1=value1&field2=value2&field3=value3 (full URL example is http://.domain.com/?field1=value1&fi...&field3=value3)
      • The query string starts with a '?' to separate it from the web page address, and each subsequent query string field/value pairs are separated by '&'

What is the difference between Redirect and Page? When should I use one or the other?

  •  Redirect functions by visitors completing your Gravity Form outside your domain briefly to your Act-On Proxy URL. This gives Act-On time to accept the data being submitted, and to update the cookie on the visitors' browser. They are then sent back to your pre-defined response page, but the process takes a fraction of a second and during that time you may see a rapid page navigation occur in the browser.
    • This method is fine for most. However, if you are interested in the fastest performance possible or are tracking bounces via a third-party service (such as Google Analytics), you will want to use Page in all likelihood.
  • Page allows the form to submit data to Act-On without bouncing your site visitors outside your domain and onto the Act-On form response page. It is slightly faster as a result. It works by creating a hidden one-pixel iframe on your WordPress form response page that captures the query string in your URL and passes it to Act-On (the iframe being used allows us to update the visitor's browser cookie).

 

I'm using the Page steps and am unable to get the JavaScript to work on my response page. Why?

Running a unique JavaScript on a specific page in WordPress may require some setup if your WordPress account or configuration is set to disallow JavaScript by default. Web developers familiar with WordPress' PHP template files are encouraged to follow the official documentation provided by WordPress for embedding permanent scripts.

This strategy uses the Gravity Forms Developer: gform_after_submission hook, which will be added to your WordPress functions.php file. This allows you to make more flexible connections with Act-On that exist behind the scenes, and avoid having your WordPress set specific Gravity Forms settings via the Gravity Forms administration interface.

The example below is adapted from the PHP sections on the article Posting External Forms to Act-On

Steps required:

Step 1:

For each form this is used with, we need an equivalent "mirror" version of the Form to be created within Act-On. For example, if your custom form on your website captures First Name, Last Name, and Email, you'll need to create a form within Act-On that also requests these fields. Your website visitors will never see this Act-On variant of your form -- we simply need to receive your custom form’s data.

In each field in your Act-On "proxy" form, note the "Data Field Name". You can see the Data Field Name by clicking each form field in the form editor to bring up the field settings. We will be needing this Data Field Name in the functions.php code addition below.

Step 2:

You'll want to grab your Act-On form's external post URL. This is located under Content > Form Post URLs. The external post URL is unique from your form's public URL, and is designed specifically for accepting incoming external submissions.

Step 3:

In your WordPress admin interface, navigate to the editor for your Gravity Forms and note the field IDs. Your field ID can be seen in the header of the Gravity Forms form editor if you click it to expand it:

Step 4:

Next you will want to paste the following code into a valid spot of your theme's functions.php file:

Class to implement: 


/* Post form submission data to Act-On and convert visitors to known via 1px by 1px hidden iframe that is 
* generated programatically. The iframe src contains a query-string to pass form field values into Act-On.
* Assumes PHP version 5 or newer
*/

class ActonWordPressConnection 

{
  private $_postItems = array(); 
  private function getPostItems() 
  {
    return $this->_postItems;
  }

  /**
 * for setting your form's POST items (key is your form input's name, value is the input value)
  * @param string $key first part of key=value for form field submission (name in name=John)
  * @param string $value latter part of key=value for form field submission (John in name=John)
  */
  public function setPostItems($key,$value)
  {
    $this->_postItems[$key] = (string)$value;
  }

  /**
  * process form data for submission to your Act-On external form URL
  * @param string $extPostUrl your external post (Proxy URL) for your Act-On "proxy" form
  */
  public function processConnection($extPostUrl)
  {
    $fields = http_build_query($this->getPostItems()); // encode post items into query-string
    $extPostUrlWithQueryString = $extPostUrl . '?' . $fields; // assemble full URL w/ query-string of submission key-values for GET to Act-On
    $hiddenIframe = "<iframe style='position: absolute; bottom: 0px; right: 0px; border: none; height: 1px; width: 1px; background: none' src=" . $extPostUrlWithQueryString . "></iframe>"; // assemble hidden iframe containing URL to pass form submission data and update visitor's cookie value thru iframe
    echo $hiddenIframe;
  }
}
 

 

If you do not have a preferred location for custom classes, this can be pasted at the bottom of your functions.php file (but before the closing "?>" tag -- we don't want to remove that!). You only need to paste this code in once.

Note: This is the same class as utilized for the WP-members API integration, though implementation is different for Gravity Forms (to accommodate the Gravity Forms API).

Example implementation of above class:


add_action('gform_after_submission', 'send_to_acton', 10, 2);
function send_to_acton($entry,$form) 
{
// declare new ActonWordPressConnection object
$ao_gf1 = new ActonWordPressConnection;

// format: setPostItems('your Act-On data field name','your custom form html input name')
$ao_gf1->setPostItems('First Name',$entry['1.3']); // HTML input name attribute is "First Name", Act-On data field name should match that
$ao_gf1->setPostItems('Last Name',$entry['1.6']); // please note that Act-On does not accept filed names with punctuation marks in them, so rename as necessary
$ao_gf1->setPostItems('E-mail Address',$entry['2']);

// processConnection method, with your external post URL passed as the argument
$ao_gf1->processConnection('http://www.actonsoftware.com/acton/e...01/d-ext-0001');
}
 

Please reference the code notes for the above. Remember to reference your specific input's Data Field Names as the first argument for each setPostItem.

Regarding field names for Gravity Forms: Note how they use digits for some fields (such as X.3 or X.6 for first and last name). You can read more about these entry objects here, but here is a quick overview of them:

  • In the Gravity Forms First/Last name block (where you have both first and last name in the same block), your first name will be X.3, and last is X.6. X is your field ID, as shown earlier in this article.
  • For checkbox blocks in Gravity Forms, your first checkbox is X.1, your second checkbox is X.2, and so on. Please see Frequently Asked Questions in the External Posting article for more information on handling checkboxes, as they are slightly different form other field types.

If you have multiple Gravity Forms, you will want to create a new class-implementation for each form. You will also want to adjust the gform_after_submission API hook function name to reference a specific Gravity Form in cases where you have more than one form on your WordPress site.

WP-Members

WP-Members is a popular, free plugin to create a membership framework for your WordPress site if you hope to restrict content access to registered members only.

Please note that these integration steps are intended for web-developers, and it involves making edits to the WordPress functions.php file

Steps required:

Step 1:

For each form this is used with, we need an equivalent "mirror" version of the Form to be created within Act-On. For example, if your custom form on your website captures First Name, Last Name, and Email, you'll need to create a form within Act-On that also requests these fields. Your website visitors will never see this Act-On variant of your form -- we simply need to receive your custom form’s data.

In each field in your Act-On "proxy" form, note the "Data Field Name". You can see the Data Field Name by clicking each form field in the form editor to bring up the field settings. We will be needing this Data Field Name in the functions.php code addition below.

Step 2:

You'll want to grab your Act-On form's external post URL. This is located under Content > Form Post URLs. The external post URL is unique from your form's public URL, and is designed specifically for accepting incoming external submissions.

Step 3:

Next you will want to paste the following code into a valid spot of your theme's functions.php file:

Class to implement: 


/**
* Post form submission data to Act-On and convert visitors to known via cURL, allowing no direct touch
* between Act-On and your website vistitor's browser to be necessary
*/
class ActonWordPressConnection
{
protected $_postItems = array();

protected function getPostItems()
{
return $this->_postItems;
}

/**
* for setting your form's POST items (key is your form input's name, value is the input value)
* @param string $key first part of key=value for form field submission (name in name=John)
* @param string $value latter part of key=value for form field submission (John in name=John)
*/
public function setPostItems($key, $value)
{
$this->_postItems[$key] = (string)$value;
}

protected function getDomain($address)
{
$pieces = parse_url($address);
$domain = isset($pieces['host']) ? $pieces['host'] : '';
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs))
{
return $regs['domain'];
}

return false;
}

// get IP of website visitor to send to Act-On for location info

protected function getUserIP()
{

// check proxy

if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}

return $ip;
}

/**
* process form data for submission to your Act-On external form URL
* @param string $extPostUrl your external post (Proxy URL) for your Act-On "proxy" form
*/
public function processConnection($extPostUrl)
{

// get the account ID from $extPostURL

$acctIdWithPath = preg_replace('/^(.*?)eform\//', '', $extPostUrl); // remove extPostUrl string parts up to 'eform/'
$acctId = explode('/', (string)$acctIdWithPath, 2); // remove parts after the first /, which leaves the acct ID remaining
$aoCookieName = 'wp' . $acctId[0];
$aoCookieNameOI = 'ao_optin' . $acctId[0]; // if opt-in cookie is enabled
if (isset($_COOKIE[$aoCookieName]))
{
$aoCookieToSend = new WP_Http_Cookie();
$aoCookieToSend->name = $aoCookieName;
$aoCookieToSend->value = $_COOKIE[$aoCookieName];
$aoCookiesToSend[] = $aoCookieToSend;
if (isset($_COOKIE[$aoCookieNameOI]))
{
$aoCookieToSendOI = new WP_Http_Cookie();
$aoCookieToSendOI->name = $aoCookieNameOI;
$aoCookieToSendOI->value = $_COOKIE[$aoCookieNameOI];
$aoCookiesToSend[] = $aoCookieToSendOI;
}

$this->setPostItems('_ipaddr', $this->getUserIP()); // Act-On accepts manually defined IPs if using field name '_ipaddr'
$fields = http_build_query($this->getPostItems()); // encode post items into query-string
$request = wp_remote_get($extPostUrl . '?' . $fields, array(
'cookies' => $aoCookiesToSend
));
$aoResponseCookie = explode(";", (string)$request["headers"]["set-cookie"]);
foreach($aoResponseCookie as $key => & $value)
{
$splitAtEquals = explode('=', (string)$value);
$newKey = $splitAtEquals[0]; // set array keys to named keys (wpXXXX, Version, Domain, Max-Age, Expires, Path)
$aoResponseCookie[$newKey] = $value;
$newValue = preg_replace('/^(.*?)=/', '', $value);
$value = $newValue;
}

setrawcookie($aoCookieName, $aoResponseCookie[$aoCookieName], time() + 86400 * 365, "/", $this->getDomain($extPostUrl));
}
}
}
 

If you do not have a preferred location for custom classes, this can be pasted at the bottom of your functions.php file (but before the closing "?>" tag -- we don't want to remove that!). You only need to paste this code in once.

This is the same class as utilized for the Gravity forms API integration.

For the class implementation however, we will want two instances -- one for those registering, and one for those logging in (who have previously registered). This is because WP-Members uses a different hook for each case.

Example implementation of above class for new registrations from WP-Members:


add_action('init', 'process_post');
function process_post(){

add_action( 'wpmem_post_register_data', 'my_reg_hook', 1 );
function my_reg_hook( $fields )
{

$ao_wp_mem_reg = new ActonWordPressConnection;
$ao_wp_mem_reg->setPostItems('First Name',$fields[first_name]); // HTML input name attribute is "First Name", Act-On data field name should match that
$ao_wp_mem_reg->setPostItems('Last Name',$fields[last_name]); // please note that Act-On does not accept filed names with punctuation marks in them, so rename as necessary
$ao_wp_mem_reg->setPostItems('E-mail Address', $fields[user_email]);
$ao_wp_mem_reg->processConnection('http://subdomain.domain.com/acton/ef...57/d-ext-0001'); // your external post URL ("Proxy Form URL")

}
}

Please reference the code notes for the above. Remember to reference your specific input's Data Field Names as the first argument for each setPostItem.

The above uses two different hooks, with the WP-Members registration hook nested inside a WordPress init hook:

  • The WordPress init hook is used, because we need to set the Act-On cookie value (which must be done inside the http headers)
  • Nested inside that, the WP-Members registration hook wpmem_post_register_data fires once the form submit has passed validation and has been written to your WordPress database, but before the WP-Members confirmation email has been sent

Example implementation of above class for logins for existing members from WP-Members:


add_action('init', 'process_post');
function process_post(){

add_action( 'wpmem_post_update_data', 'my_reg_hook', 1 );
function my_update_hook( $fields )
{

$post1 = new ActonWordPressConnection;
$post1->setPostItems('First Name',$fields[first_name]); // HTML input name attribute is "First Name", Act-On data field name should match that
$post1->setPostItems('Last Name',$fields[last_name]); // please note that Act-On does not accept filed names with punctuation marks in them, so rename as necessary
$post1->setPostItems('E-mail Address', $fields[user_email]);
$post1->processConnection('http://subdomain.domain.com/acton/ef...57/d-ext-0001'); // your external post URL ("Proxy Form URL")

}
}

Please reference the code notes for the above. Remember to reference your specific input's Data Field Names as the first argument for each setPostItem.

The above uses two different hooks, with the WP-Members update hook nested inside a WordPress init hook:

  • The WordPress init hook is used, because we need to set the Act-On cookie value (which must be done inside the http headers)
  • Nested inside that, the WP-Members registration hook wpmem_post_update_data fires once the form submit has passed validation and has been written to your WordPress database, but before the WP-Members confirmation email has been sent

Note: If you are not sure what the field names are for your WP-Members form submissions, place the following line inside the WP-Members hook function and it will print them out for you on your next submission:


echo "<pre>"; print_r( $fields ); echo "</pre>";

/* BELOW: The default printout of the above $fields array, if you use default fields for the WP-members registration form */

Array 

[username] => x 
[user_email] => x 
[first_name] => x 
[last_name] => x 
[addr1] => x 
[addr2] => x 
[city] => x 
[thestate] => x 
[zip] => x 
[country] => x 
[phone1] => x 
[password] => x 
[user_registered] => x 
[user_role] => x 
[wpmem_reg_ip] => x 
[wpmem_reg_url] => x 
[user_nicename] => x 
[display_name] => x 
[nickname] => x 
[ID] => 16 
[user_url] => 
)

Other WordPress form plug-ins or systems

If you are using a WordPress forms system not referenced above, you are encouraged to adapt one of the above-referenced methods in this article. Most WordPress form plugins have an API, and typically one of the API hooks enables a developer to add functions once the form has completed validation of a submission (this is what we are using for WP-Members and Gravity Forms).

  • Was this article helpful?