mermberfix logo x
The MemberFix Team’s got you covered.
Membership plugins

How to send a GravityForms parameter to an external site

How to send a GravityForms parameter to an external site



One of our MemberFix customers recently came to us with a unique use case in which she wanted to send pre-populated affiliate ID values from her core website, to an affiliate partner’s website. The affiliate partner’s website already had tech that would then grab the affiliate ID for their referral program tracking.

In our customer’s words:

Affiliates that we work with will also receive commissions through our partners and we need a way to track this internally. We have our partners set up so that when a link is clicked it has a CID code on the link and from that point it’s being tracked (we don’t have to do anything else – our partner is doing all the tracking at that point).

So, we need a way for the member to always be associated with that affiliate (the affiliate will also receive lifetime commissions on that member). My thought is we can do this by tracking the Affiliate #. Put a hidden field on MemberPress that will automatically populate with the affiliate # when they register. And what is the meta data field name that can then be used as the CID?

This particularly savvy customer had the right idea!

The core website has the following apps:

Shortly the whole process is this:

  1. An user subscribes to her website and becomes a MemberPress member.
  2. The registration form for the user it is a Gravity Forms one with a hidden input field for the case when the new user was referred by an affiliate, which means that the new user landed on customer’s website from a link like this: where “mepr_affiliate” is the ID of the affiliate which referred the new user. Then the Gravity Forms hidden input field is added to the database.
  3. MemberPress needs to be connected to AffiliateWP and AffiliateWP needs to be connected to Gravity Forms. I will explain below how we can easily do that.
  4. The the final part where the whole magic happens is that the customer has a page on the website which it is accessed by the MemberPress users and there is a form which every member can submit it and this will make the ID of the affiliate which referred the member is sent to an external website. As I said above this is needed for the referral program tracking.

Let’s see all the steps in more detail!

MemberPress integration with AffiliateWP

First of all MemberPress needs to be integrated with AffiliateWP and all you need to do is go to Affiliates > Settings > Integrations and check the MemberPress box:

memberpress integration with affiliatewp 1 - How to send a GravityForms parameter to an external site

Once enabled, AffiliateWP will automatically generate referral records when a customer successfully registers for your site after clicking on a referral link.

AffiliateWP integration with Gravity Forms

For this integration we will use Affiliate Forms For Gravity Forms add-on. After you install the add-on just go again to Affiliates > Settings > Integrations and check the Gravity Form box as you have seen in the above image.  When you build the form with Gravity Forms you are able to add an input hidden field like in the below image:

affiliatewp parameter - How to send a GravityForms parameter to an external site

“mepr_affiliate” is the URL variable for AffiliateWP referral URLs which can be defined in AffiliateWP > Settings > General as shown below:

affiliatewp link - How to send a GravityForms parameter to an external site

So, for example, if a user lands on the registration form page from a link like this – – the affiliate ID which referred this user is added to the database. If there is no parameter, then the “mepr_affiliate” hidden field will be empty.

Creating the form and WordPress PHP schortcode

Our customer (the vendor of this affiliate program) has a form on her site which is submitted to an external website that receives one of the parameters. The form looks something like this:

<form action=“” method=“POST”>
<input name=“mepraff” type=“hidden” value=“77” />
<button type=“submit”>SUBMIT FORM</button>

The objective was to dynamically update this form, for every visiting user, with the corresponding affiliate ID of the affiliate who referred them (the “mepraff” input in the above form corresponds to “mepr_affiliate” from the database). To achieve this functionality we used WordPress shortcodes and a bit of custom code in the functions.php file on the site that has MemberPress installed.

To that end, I wrote a function that shows the shortcode:

function mf_mepr_affiliate($current_user){
// retrieve the current user object
$current_user = wp_get_current_user();
// get user ID
$meta = get_user_meta( $current_user->ID );
// get the ID of the affiliate who referred user
$meta_mepr = $meta;
// return hidden filed line for the form
return ‘<input name=”mepraff” type=”hidden” value=”‘.$meta_mepr.‘” />’;
add_shortcode(‘mf_mepr_affiliate_sc’, ‘mf_mepr_affiliate’);

Then I added the form code on the web page, and inserted the required shortcode (in bold below) directly into the form code:

<form action=“” method=“POST”>
<button type=“submit”>SUBMIT FORM</button>

Now when a given user is logged in, the function above will pull that user’s “mepr_affiliate” field value from the user database and populate the “mepraff” hidden field in the form with that value. Thus, when the form is submitted to the external website, the “mepraff” hidden field is sent there, and it can be manipulated in the external website in whatever way is required.

Questions, comments, concerns? Leave your thoughts below and we’ll be around to lend a hand. 🙂

You may also enjoy...

WordPress based membership sites have certain requirements, and make use of certain applications that, in my experience, makes most of the popular hosting providers a poor choice.
Let’s get something straight: There is no “best” email marketing service, despite what page one of your Google search results might…
How to show or hide the Divi Area Popup according to content that appears on this popup.
Our review is based on actual, real world experience “in the trenches” using and working with this plugin for over 5 years!
Notify of
Inline Feedbacks
View all comments