Forum

Complete Digital Access Pass (DAP) + Gravity Forms Integration Instructions for Free or Paid Products  

  RSS
Vic Dorfman
(@admin)
Member Admin

I recently integrated Gravity Forms with DAP for a client.

I found that the official DAP documentation for Gravity forms integration is missing some details and indicates incorrect syntax for the gform_after_submission function.

So here is an updated integration doc with instructions for doing this integration.

Don't worry, this is fairly simple; just follow the step by step directions! :)

 

Please note that this works with both free and paid products (that is, paid using a Gravity forms payment add-on like Paypal or Stripe).

1. Go to DAP => Products/Levels => Manage.

Set up your DAP product as you normally would (name, description, default system pages, pricing, welcome email, integration with autoresponder, ContentResponder settings, etc.)

Once you have all your settings the way you want them, go to the 'General' tab and find the line that says "Allow Free Signup?".

Select YES.

*Note: you MUST select 'yes' in order for this integration to work. If 'Allow Free Signup' remains set to 'no', members will NOT get added to DAP after submitting the Gravity Form, even if every other aspect of this integration is done correctly.

2. Go to WordPress => Forms and set up your Gravity Form any way you want.

3. Get the field ID numbers for each form field in your Gravity Form.

Go to WordPress => Forms => Mouse over your form => Mouse over 'Settings' => Click on 'Notifications'.

Mouse over 'Admin Notification' and click 'Edit'.

Scroll down to the 'Message' field and locate the little icon to the right of the field, as shown in this screenshot:

 

 

Click on each of the fields you want to pass to DAP (at the very least you have to pass 'email' and 'first_name' but you can pass a bunch of additional custom fields if you want, though it's not required).

Note the number after the colon for each field. For example, in my system, here's what I get for email, first_name and last_name:

{Name (First):1.3}

{Name (Last):1.6}

{Email:2}

*If the only fields you need to pass to DAP from the Gravity Form submission are 'email' (required), 'first_name' (required), 'last_name' (optional), then you don't need to create custom fields in DAP to correspond to these fields, as they already exist in DAP by default.

If, however, you want to pass some custom fields like Gender, Occupation, etc., then you will need to create the corresponding custom fields in DAP.

To do this, simply go to DAP => Users => Custom Fields and fill out the form as many times as you need to create all of your custom fields.

4. Add the gform_after_submission function to your theme's functions.php file.

Go to WordPress => Appearance => Editor.

Click on the 'functions.php' link in the templates listing on the right hand side of the screen:

 

 

Add the following snippet of code to the very bottom of the functions.php theme file:

add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {

$post_url = 'http://www.vicdorfman/dap/signup_submit.php';
$body = array(
'productId' => '3',
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar ( $entry, '1.6' ),
'email' => rgar( $entry, '2' ),
);

GFCommon::log_debug( "post_to_third_party(): body => " . print_r( $body, true ) );

$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );

GFCommon::log_debug( "post_to_third_party(): response => " . print_r( $response, true ) );
}

 

***VERY IMPORTANT NOTES ABOUT SYNTAX!!***

PHP is very sensitive to syntax (the exact way something is written).

So please adhere to these notes or your site will crash.

If you accidentally crash your site, as I did the first few times haha, you'll get the white screen of doom.

Don't worry. Just go edit the functions.php file via your cPanel or via FTP.

(You can find it in /public_html/yoursite.com/wp-content/themes/functions.php)

 

A) Your functions.php file MUST begin with '' at the end of the functions.php file. If it's there, delete it.

C) Do not separate functions with a ' class Op_Arrow_Walker_Nav_Menu extends Walker_Nav_Menu
{
public function display_element($el, &$children, $max_depth, $depth = 0, $args, &$output)
{
$id = $this->db_fields['id'];

if(isset($children[$el->$id])) {
$el->classes[] = 'has_children';
}

parent::display_element($el, $children, $max_depth, $depth, $args, $output);
}
}
}

add_action( 'gform_after_submission_2', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {

$post_url = 'http://www.vicdorfman/dap/signup_submit.php';
$body = array(
'productId' => '3',
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar ( $entry, '1.6' ),
'email' => rgar( $entry, '2' ),
);

GFCommon::log_debug( "post_to_third_party(): body => " . print_r( $body, true ) );

$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );

GFCommon::log_debug( "post_to_third_party(): response => " . print_r( $response, true ) );
}

*Important Stuff:

=> replace ' http://www.vicdorfman.com/dap/signup_submit.php ' in the first line of the code snippet with 'http://www.yoursite.com/dap/signup_submit.php' where 'yoursite' is your website URL.

=> for the productID => '3' entry, replace '3' with your DAP product ID (which you can find by going to DAP => Products/Levels => Manage => Select your product => Product Id is displayed above Product Name.

=> For the 'first_name', field, last_name field, email field, and any additional custom fields you've created, make sure the values correspond to the values you pulled in step #2.

e.g. If your value for 'first_name' is '4', replace '1.3' with '4' like this:

'first_name' => rgar( $entry, '4' ),

=> Make sure to add any custom fields below the first three fields like this:

add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {

$post_url = 'http://www.vicdorfman.com/dap/signup_submit.php';
$body = array(
'productId' => '3',
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar ( $entry, '1.6' ),
'email' => rgar( $entry, '2' ),
'custom_occupation' => rgar( $entry, '5' ),
'custom_gender' => rgar( $entry, '6' ),
);

GFCommon::log_debug( "post_to_third_party(): body => " . print_r( $body, true ) );

$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );

GFCommon::log_debug( "post_to_third_party(): response => " . print_r( $response, true ) );
}

*Make sure to prepend all custom fields with 'custom_', e.g. 'custom_occupation', 'custom_gender', etc.

(It's not necessary to prepend 'phone', 'address1', or 'address2' fields with 'custom_' as these fields already exist by default in DAP.)

=> The numbers 10 and 2 at the end of the 'add_action' line are NOT the form ID. '10' is the priority the hook runs (10 is standard) and '2' is the number of arguments available ($entry and $form).

In other words, don't change this unless you know what you're doing.

You can find out more in the following WordPress codex article: http://codex.wordpress.org/Plugin_API#Hook_in_your_Filter

To have the hook run for a specific form you can append the form id on the end of the hook name like so:

add_action( 'gform_after_submission_1', 'post_to_third_party', 10, 2 );

****

That's it! Now test your form by filling it out with user information that is NOT already inside the DAP member database.

After form submission, whether free or paid, the user should be added to the specified DAP product(s).

ReplyQuote
Posted : 17/06/2018 7:19 pm
Vic Dorfman
(@admin)
Member Admin

UPDATE!

Hey all, I received an email from a reader who tried the above procedure but it didn't work.

He wrote:

Hi Vic,

I found your post on the DAP website about integration between DAP and Gravity Forms. I also saw that you had posted this update to the procedure. I followed everything step-by-step but cannot seem to get my Gravity form to add the submitted user info to the DAP database using the above step-by-step. I was wondering if you might be able to help me out with it. No error messages at all. The data gets added as a Gravity form entry inside Wordpress. It just doesn’t make it to DAP.

Thanks.
Craig

Note: The problem that Craig was experiencing was due to entering the URL incorrectly inside the snippet in the functions.php theme file.

If your integration isn’t working, double-check that you’re using the correct URL where your DAP site is located:

In my case it’s:  http://www.vicdorfman/dap/signup_submit.php

Please note that if you’re using a subdomain like  http://awesome.vicdorfman.com

then the correct URL would be  http://awesome.vicdorfman.com/dap/signup_submit.php

If your WordPress installation is in a subfolder like  http://www.vicdorfman/wordpress/  then your url would  http://www.vicdorfman/dap/signup_submit.php  (without the /wordpress) because DAP is always installed at the ROOT of your website folder.

Hope that helps!

ReplyQuote
Posted : 17/06/2018 7:21 pm
Share:
  
Working

Please Login or Register