Lead Gen & CRM
How can we help you?
Search our help articles, video tutorials, and quickstart guides

You've got this. You've got us. Search our Knowledge Base to quickly find answers to your questions.

Using Ninja Forms 3 with Lead Gen CRM

Article: 000050457
Updated: July 18, 2024

Connect Ninja Forms 3 to your Lead Gen & CRM account

Connecting Ninja Forms 3 to Lead Gen & CRM requires a different approach than normal native form embed code usage.

This article details how to use Ninja Forms 3 with Lead Gen & CRM.


Article Contents


Users:
Administrators 
Company Managers  
Marketing Managers  
Sales Managers  
Salespersons  
Jr. Salespersons  

Before You Connect

The procedures in this article assume that you have done the following:

  • Installed Ninja Forms 3 on Wordpress
  • Added a Ninja Form 3 to at least one Wordpress page
  • Inserted site tracking code on each Wordpress page you want to track

Adding the WordPress connection to Ninja Forms 3

Ninja Forms needs connected using a special method, which requires some additional code. The simplest way to do this is by uploading the plugin file found here. Note that this is offered as a way to add the code to WordPress, and the other steps are necessary, aside from copying the PHP code. If there is any issue with using this plugin on your setup, your developer will need to explore adding the PHP code below manually.

  1. Download the plugin zip file attached to this article at the bottom.
  2. In WordPress go to Plugins, and choose to upload a plugin.
  3. Upload the zip file.
  4. View your Plugins in WordPress and enable this plugin.

If this gives you issues, or you prefer to add the code in your own way, please see the steps below. By using either the plugin or a child theme, it will prevent the code from being removed if your theme updates its functions.php file.


Adding .PHP Code to Ninja Forms

Note that this is only required if not using the plugin as noted above. If using the plugin, please proceed to the Generating Native Form Embed Codes section below.

Note: Constant Contact offers Professional Services to assist with custom coding.

To connect Ninja Forms 3 with native forms in Lead Gen & CRM, you will need to modify Wordpress code.

To modify Wordpress code, do the following:

  1. Open a new tab in your web browser.
  2. Log in to Wordpress in that browser tab.  
  3. Click Appearance > Editor > Theme Functions.
  4. Open your Wordpress functions.php file.
  5. Paste the following code as-is in the functions.php file:
add_action( 'ninja_forms_after_submission', 'send_ninja_form_to_sharpspring' );
function send_ninja_form_to_sharpspring($formData){
	
	$formFields = $formData['fields_by_key'];
	
	foreach($formFields as $formField):
		if($formField['key']=='sharpspring_post_url')://if this field is the sharpspring post url
			$post_url = $formField['value'];
		
		else://it's a form field, so let's add it to the body
			
			//if they specified an admin label to make it easier to map fields in sharpspring, use it
			$trimmedName = trim($formField['admin_label']);
                        if(!empty($trimmedName)):
				$fieldNiceName = $formField['admin_label'];
			else://use the field key
				$fieldNiceName = $formField['key'];
			endif;
			
			//add this field to the body
			if($formField['type'] != 'listcheckbox' && $formField['type'] != 'listmultiselect'):
				$body[$fieldNiceName] = $formField['value'];
			else://implode values if it is a checkbox or multi-select
				$body[$fieldNiceName] = implode(',',$formField['value']);
			endif;

		endif;
		
	endforeach;
	
	$body['trackingid__sb'] = $_COOKIE['__ss_tk']; //DO NOT CHANGE THIS LINE... it collects the tracking cookie to establish tracking

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

}

 



Generating Native Form Embed Codes

You will need to generate a native form embed code to connect to Ninja Forms 3.

Note: When connecting Ninja Forms 3, you should not place the native form embed code on the page. However, you will need to generate one for each form to refer to it.

To generate native form embed codes, do the following:

  1. Open another new tab in your web browser.
  2. Log in to Lead Gen & CRM in that browser tab.
  3. Click Forms in the left toolbar.
  4. Create or edit a native form.
  5. Click  12more.png  Actions > Embed Code.
  6. Keep this code available for reference.

 



Connecting Ninja Forms 3

You will need to modify a form and connect Ninja Forms 3 with native forms in Lead Gen & CRM.

To connect to Ninja Forms 3, do the following:

  1. Open another new tab in your web browser.
  2. Access Ninja Forms in that browser tab.
  3. Create or edit a Ninja Form.
  4. Add a hidden field to your form within the Ninja Forms form editor.
  5. Set the the Field Key and Admin Label as ‘sharpspring_post_url’.
    Important: Ninja Forms' Developer Mode must be enabled in order to see and make changes to the Field Key and Admin Label.
  6. Combine the baseURI and endpoint values to form the post URL for this form.
  7. Set the Default Value to the post URL for this form.
  8. Set the post URL as the Default Value for the hidden field.
  9. Optionally, give an Admin Label to each of your fields.
  10. Save and submit the form.
  11. Return to the Lead Gen & CRM browser tab.
  12. Map the form within Lead Gen & CRM. 

Ninja Form Hidden Field


Post URL Example

When forming the post URL, the baseURI and endpoint code should appear similar to the following example code:
 

 __ss_noform.push(['baseURI', 'https://app-3Q4K3MJUEA.marketingautomation.services/webforms/receivePostback/MzYwNzKzMDM0BAA/']);
    __ss_noform.push(['endpoint', 'f65d1953-da63-489b-8b68-9d1684a8d93b']);


When combined, this creates the following post URL:
 

https://app-3Q4K3MJUEA.marketingautomation.services/webforms/receivePostback/MzYwNzKzMDM0BAA/f65d1953-da63-489b-8b68-9d1684a8d93b

 



Form Considerations

When connecting Ninja Forms 3, keep in mind the following:

  • Take care when mapping fields. Adding Admin Labels makes it easier when mapping within Lead Gen & CRM. This will appear in Lead Gen & CRM instead of the field ID when mapping. While optional, this can make it more clear which field is which when mapping if the values sent do not make it obvious.
     
  • Individual form codes are needed. When adding additional Ninja Forms, you do not need to do the step of adding code to functions.php, as the one code block will handle all forms. Any form with a hidden field called ‘sharpspring_post_url’ that contains a valid URL should be able to be mapped and then captured into Lead Gen & CRM. Ensure that you use a new native form code to create the post URL for each form, as those should be unique.
     
  • Be careful when modifying Wordpress. Be aware that if any Lead Gen & CRM native form code had been placed on the page for this form previously, it should be removed, as it will interfere. Additionally, changes to functions.php can result in a site failing to load, including the WordPress login page. You should be prepared to revert to your previous functions.php via FTP should any errors prevent the site from loading. 


Download The Plugin


Did this article answer your question?


Constant Contact Logo

Copyright © 2025 · All Rights Reserved · Constant Contact · Privacy Center