Passing URL String Variables to Prefill an Ontraport Form

If you are using the “Javascript Snippet” method of getting a Ontraport Smart form onto your WordPress page and want to automatically fill in a field on the form (e.g., firstname) using a URL string variable (e.g., ?fn=John), I got it to work using the following Javascript:

<script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
window.onload = setVar;
function setVar() {
var theform = document.getElementsByTagName("form");
theform[0].elements["firstname"].value=getParameterByName("fn");
}
</script>

Note: this assumes there’s one form on the page. If there are multiple forms on the page, the first one is referenced by theform[0], the second one by theform[1], etc.

Note 2: works with both visible and hidden form fields (I’m actually using it with a hidden field).

Note 3: make sure to put this script in the HEAD section of the page.

Integrating a WordPress Forum with Pilotpress Membership Levels

Let’s say you’ve created a membership website using Pilotpress (Ontraport’s WordPress membership plugin) and you would like to add a member forum. But you don’t just want a members-only forum (though you want that too) , you want to add multiple forums and/or sub-forums and have them be accessible only to certain Pilotpress membership levels–i.e., each forum/sub-forum can only be accessed by members in one or a few select Pilotpress membership levels.

When my company was still using the Wishlist Member membership plugin, the least expensive forum option we could find to work with WordPress and Wishlist Member was SimplePress. So, that’s what we used.

Upon moving from Wishlist Member to Pilotpress for our member website, we weren’t sure if SimplePress would still be our best option…though it would be easiest if we *could* make it work so we wouldn’t have to spend time configuring a new forum and trying to move posts and users to it.

Giving Pilotpress users access to SimplePress wasn’t a problem because new PilotPress logins generate new WordPress logins, and you can have SimplePress automatically assign new WordPress users/subscribers access to one or more forums.

The problem is you can only select one group to assign them to–i.e., you can select one group for all new members/subscribers to be assigned to.

But what if you want different Pilotpress membership levels to be assigned to different groups?…with only certain groups having access to certain forums/sub-forums? If we could come up with a way of doing this, we could continue to use the SimplePress forum plugin.

After digging into the SimplePress plugin code and doing some tests with the shortcodes provided by the PilotPress plugin, we developed a solution.

The Solution

First, we had to come up with a way to assign the currently logged in user to a previously set up SimplePress user group using a shortcode. So I developed a WordPress plugin that does just that. The shortcode it makes available looks like this:

[add_to_sp_group id=”19″]

..where id is the ID of the SimplePress group you want the user added to (the SimplePress group IDs are listed in SimplePress’s admin interface).

Second, we had to set up a way to assign users to SimplePress groups depending on their PilotPress membership level. We determined it could be done in conjunction with the PilotPress plugin in two ways:

  1. If there is a base/home page that only someone in a certain membership level can get to, and it’s a page that all users in that membership level have to pass through to get to any other of their protected pages, the “add_to_sp_group” shortcode can simply go on that page, and they’ll be added to the appropriate group upon visiting this page.
  2. The second method involves using the [show_if has_one=”Many,levels”] content [/show_if] shortcode provided by Pilotpress, on a page that all users logging into the member website have to pass through on their way to any other page in the membership website. For example:

[show_if has_one=”Gold”] [add_to_sp_group id=”3″] [/show_if]

…will assign the user to the SimplePress group with ID=3 if they are in the “Gold” Pilotpress membership level.

There is also a [remove_from_sp_group id=”3″] shortcode we made available in case there’s a reason to remove someone from a SimplePress group (for example: they moved to a new higher level membership and should not be participating in the forum at the lower membership level anymore).

BuddyPress Now Included Too!

Someone requested I include code in the plugin that works with the BuddyPress forum plugin. It turns out to be similar to what was needed for SimplePress, so new shortcodes for BuddyPress have been included too.

The new shortcodes are very similar to the shortcodes for SimplePress, except they use the abbreviation “bp” instead of “sp”. So, for example, to add someone to group with ID=4, you would use the following shortcode:

[add_to_bp_group id=”4″]

Requirements

The requirements to make this work are:

  • A WordPress website
  • An Ontraport account
  • Pilotpress installed at your WordPress website
  • SimplePress or BuddyPress installed at your WordPress website
  • The Forum Group Assign plugin installed* at your WordPress website
  • The creation of some forums or sub-forums and some groups in SimplePress or BuddyPress, along with assigning specific groups to specific forums
  • The creation of Pilotpress membership levels in Ontraport for the WordPress website

Once you’ve got all of these elements in place, you can start using the Forum Group Assign shortcode as described above.

If you find this plugin useful and would like to encourage me to provide other useful plugins for Ontraport and Pilotpress, please consider sending your appreciation to my PayPal account
( $5 / $10 / $15 )
..😀.

*Installing a downloaded zipped WordPress plugin file:

From the WordPress plugin menu click on Add New:

Instead of searching for a plugin you can directly upload your
plugin zip file by clicking on Upload:

Use the browse button to select the plugin zip file that was downloaded, then click on Install Now. The plugin will be uploaded to your blog and installed. It can then be activated (find it on the Installed Plugins page and click the “activate” link under the plugin called “Forum Group Assign“).

Smart Form Prefill: An Ontraport + WordPress Shortcode Plugin

I wrote a WordPress plugin that renders an Ontraport smart form at my WordPress website using a shortcode that looks like:

[op_smartform id=”1″]

..where id is the ID of the smart form in the Ontraport app. Using a shortcode to specify a form versus a javascript snippet is helpful for us in a couple of ways, one of which is that I don’t have to actually go into a form and then to “publish” to get the code from the Ontraport app, I just have to hover my mouse over the form link in the listing of forms to get the ID.

While I was at it, I added the additional feature that the form will automatically prefill with the user’s contact info if they have an Ontraport cookie at my website as the result of having filled out some other form at my website in the past (or if they’ve logged into Pilotpress). This automatic prefill feature is the default behavior of the shortcode.

If I don’t want the form to prefill and/or want the form to render faster (it takes a little longer for it to prefill, though it’s not too slow even then), I’ve added a “switch” to turn off prefilling:

[op_smartform id=”1″ prefill=”no”]

Using the Plugin at your WordPress website

  1. You need to have an Ontraport account
  2. It’s a good idea to install a Ontraport tracking script at your WordPress website–or alternatively, install the Pilotpress plugin
  3. In Ontraport, generate a new API Key for the website where you will be using the plugin (if you haven’t already)
  4. Purchase and download the Smart Form Prefill plugin (the order form is also at the bottom of this post)
  5. Install and activate* the Smart Form Prefill plugin
  6. Go to Settings > “Smart Form Prefill” in the WordPress dashboard at the website where you’ll be using the plugin and put in the API key codes from #3 above and save them.

Some Code Examples

• Render an Ontraport Smart Form with ID=4 and Prefill with Contact data if contact is cookied:

[op_smartform id=”4″]

• Render an Ontraport Smart Form with ID=4 and *don’t* Prefill with Contact data:

[op_smartform id=”4″ prefill=”no”]

Operational Notes

  • If no browser cookie exists for your website visitor (i.e., they haven’t filled out a form at your website; or they have, but now they’re using a different computer or browser), then the form will be rendered but not prefilled.
  • The plugin includes error messages if you forget to specify a form ID in your shortcode, or you specify one that doesn’t exist in your Ontraport account.
  • If you are creating and destroying browser cookies in the process of testing the shortcodes and they don’t seem to be working, make sure you clear the cache at your WordPress website if you are using one of those WordPress website caching plug-ins.
  • You only pay for the plugin once and will receive all/any future updates to the plugin.
  • Please email me at mgm at WordPressAndOntraport.tech if you have any questions or run into any problems trying to install the plugin.

Customer Case Studies

I’m really interested to hear how people end up using the plugin. Please come back to this post and share your stories (as comments on this post) about how you’re the plugin to do interesting and creative things!


*Installing a downloaded zipped WordPress plugin file:

From the WordPress plugin menu click on Add New:

Instead of searching for a plugin you can directly upload your
plugin zip file by clicking on Upload:

Use the browse button to select the plugin zip file that was downloaded, then click on Install Now. The plugin will be uploaded to your blog and installed. It can then be activated (find it on the Installed Plugins page and click the “activate” link under the plugin called “Smart Form Prefill”).

The Order Form