Gravity Forms is an advanced form builder for Wordpress websites and can be placed into the Wordpress functions.php file. These forms can integrate with Lead Gen & CRM forms.
This article will detail how to connect Gravity Forms to Lead Gen & CRM.
Article Contents
Trial | ✓ | |
Essential | ✓ | |
Advanced | ✓ | |
Ultimate | ✓ |
Administrators | ✓ | |
Company Managers | ||
Marketing Managers | ||
Sales Managers | ||
Salespersons | ||
Jr. Salespersons |
Important Information Regarding Native Form Scripts
The Native Form script that Lead Gen & CRM provides should not be placed on your page. It is only used to complete the procedures in this document.
The provided script is only used for reference, and it should not be on the page when connecting Gravity Forms via this method. The modified Wordpress .PHP code replaces what Lead Gen & CRM's Native Form script would normally do. If both are present, your form will not function as intended.
Before You Connect
The procedures in this article assume that you have done the following:
- Installed Gravity Forms on Wordpress
- Added a Gravity Form to at least one Wordpress page
- Inserted site tracking code on each Wordpress page you want to track
Be aware that if you have existing Gravity Forms that were connected using connecting using Lead Gen & CRM's Gravity Forms Integration Tool, you will need to use the tool to generate code for new forms.
The Gravity Forms Integration Tool generates a block of code for each form you intend to add. If you were to use this tool for new forms, you would need to remove the .PHP code in the forms and add two hidden fields to each of your Gravity Forms.
Creating Native Forms
Before you can connect Gravity Forms to Lead Gen & CRM, you need to create a native form. To create native forms, do the following:
|
The created native form will open a page with an embed code. Keep this embed code window open. You will need the embed code later.
Example Native Form Code
The following is an example of native form embed code. Be aware that your code and its individual values will be different from the following example code:
<script type="text/javascript">
var __ss_noform = __ss_noform || [];
__ss_noform.push(['baseURI', 'https://app-3QN7QJRNDE.marketingautomation.services/webforms/receivePostback/MzawMDE1tTA2BQA/']);
__ss_noform.push(['endpoint', 'ea960f18-cd20-4c6c-acab-4e6b6a959260']);
</script>
<script type="text/javascript" src="https://koi-3QN7QJRNDE.marketingautomation.services/client/noform.js?ver=1.24" ></script>
Adding baseURI Embed Code to Gravity Forms
Once you have created a native form in Lead Gen & CRM, you can begin connecting Gravity Forms. The connection process requires that you add both baseURI
and endpoint
information in connected forms. This information comes from the embed code generated by the created native form in Lead Gen & CRM. To add baseURI
information to Gravity Forms, do the following:
|
![]() Example code used. Click to enlarge. |
|
Note: When copying the
baseURI string, do not include the single quotation marks. |
||
Note: For best results, make these hidden fields the first fields on your form.
|
||
Be aware that endpoint
information is still needed to complete the connection process.
Adding Endpoint Embed Code to Gravity Forms
Once you have added baseURI
information to Gravity Forms, you will need to add endpoint
information. This information comes from the embed code generated by the created native form in Lead Gen & CRM. To add endpoint
information to Gravity Forms, do the following:
|
![]() Click to enlarge. |
|
Note: When copying the
endpoint string, do not include the single quotation marks. |
||
Note: For best results, make these hidden fields the first fields on your form.
|
||
Adding .PHP Code to Gravity Forms
Once you have added baseURI
and endpoint
information to Gravity Forms, you will need to add .PHP code to Wordpress.
There are certain things to consider when adding .PHP code to Wordpress, however:
- You need to add .PHP code only once. If you add this code for each form, it would cause any number of issues. In addition, the main advantages of adding code to Wordpress are that you need only add the code once without editing it and do not modify the .PHP code otherwise. As such, when adding additional forms, you will only need to make a new native form in Lead Gen & CRM and add the two hidden fields to your Gravity form.
- You should add the .PHP code to a Wordpress child theme, if at all possible. Modifying code works best with a Wordpress child theme. Modifying a child theme allows you to modify Wordpress without breaking its functionality.
To modify Wordpress .PHP code, do the following:
|
Important: Changes to the functions.php file in Wordpress can result in your site crashing. Be sure you have FTP access in order to backup and revert to your old functions.php file if needed.
|
add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ){
if ( rgar( $entry, 'status' ) === 'spam' ) {
return false;
}
$body = [];
function dupeCheck($fieldName, $bodyData) {
$cleanLabel = substr(preg_replace("/[^a-zA-Z0-9]+/", "", $fieldName), 0, 24);
for ($x = 0; $x <= 20; $x++) {
if(array_key_exists($cleanLabel, $bodyData)) {
$cleanLabel = $cleanLabel . $x;
} else { break; }
}
return $cleanLabel;
}
$formFields = $form['fields'];
foreach($formFields as $formField):
if($formField['label'] == 'sharpspring_base_uri') {
$base_uri = rgar( $entry, $formField['id']);
$sendToSharpSpring = true;
} elseif($formField['label'] == 'sharpspring_endpoint') {
$post_endpoint = rgar( $entry, $formField['id']);
} elseif($formField['type'] == 'multiselect') {
$fieldNumber = $formField['id'];
$fieldLabel = dupeCheck($formField['label'], $body);
$tempValue = rgar ( $entry, strval($fieldNumber) );
$trimmedValue = str_replace('[', '', $tempValue);
$trimmedValue = str_replace(']', '', $trimmedValue);
$trimmedValue = str_replace('"', '', $trimmedValue);
$body[preg_replace("/[^a-zA-Z0-9]+/", "", $fieldLabel)] = $trimmedValue;
} elseif($formField['inputs']) {
if($formField['type'] == 'checkbox') {
$fieldNumber = $formField['id'];
$fieldLabel = dupeCheck($formField['label'], $body);
$checkBoxField = GFFormsModel::get_field( $form, strval($fieldNumber) );
$tempValue = is_object( $checkBoxField ) ? $checkBoxField->get_value_export( $entry ) : '';
$trimmedValue = str_replace(', ', ',', $tempValue);
$body[preg_replace("/[^a-zA-Z0-9]+/", "", $fieldLabel)] = $trimmedValue;
} elseif($formField['type'] == 'time') {
$fieldNumber = $formField['id'];
$fieldLabel = dupeCheck($formField['label'], $body);
$body[preg_replace("/[^a-zA-Z0-9]+/", "", $fieldLabel)] = rgar( $entry, strval($fieldNumber) );
} elseif($formField['type'] == 'date') {
$fieldNumber = $formField['id'];
$fieldLabel = dupeCheck($formField['label'], $body);
$body[preg_replace("/[^a-zA-Z0-9]+/", "", $fieldLabel)] = rgar( $entry, strval($fieldNumber) );
} else {
foreach($formField['inputs'] as $subField):
$fieldLabel = dupeCheck($subField['label'], $body);
$fieldNumber = $subField['id'];
$body[preg_replace("/[^a-zA-Z0-9]+/", "", $fieldLabel)] = rgar( $entry, strval($fieldNumber) );
endforeach;
} } else {
$fieldNumber = $formField['id'];
$fieldLabel = dupeCheck($formField['label'], $body);
$body[preg_replace("/[^a-zA-Z0-9]+/", "", $fieldLabel)] = rgar( $entry, strval($fieldNumber) );
};
endforeach;
$body['form_source_url'] = $entry['source_url'];
$body['trackingid__sb'] = $_COOKIE['__ss_tk']; //DO NOT CHANGE THIS LINE... it collects the tracking cookie to establish tracking
$post_url = $base_uri . $post_endpoint;
if($sendToSharpSpring) {
$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
}
}
|
Mapping Native Forms
Once you have created a native form, added native form embed code, and modified Wordpress' functions.php file, you can map the fields in the native form. Mapping form fields provides Lead Gen & CRM with information on what those form fields refer to. To map native forms, do the following:
|
Whenever you fill out the form for the first time, you generate mapping data. As such, do not expect the lead to appear in the system until after the first entry. The second person to fill out the form will be imported as a lead.
Special Considerations for Gravity Forms
When mapping fields and connecting Gravity Forms, consider the following:
- Certain fields will not be mappable. As with any non-Constant Contact form, certain fields, including the GDPR Consent and File Upload fields, will not be available for mapping.
- You may see some fields that are not on your form. For example, if you are using Gravity Forms’ default Name field, your form may only show the First Name and Last Name fields. However, this field has options to include other fields, such as Suffix or Middle Name. Skip mapping those fields if they are not on your form. This applies to any of Gravity Forms’ fields that contain multiple fields within themselves. Lead Gen & CRM only collects what is mapped.
- Your field names will appear the same as in Gravity Forms, but any non-alphanumeric characters will be removed. For example, if your Gravity Form field is What is your favorite color?, the mapping screen will show Whatisyourfavoritecolor. This only appears on the mapping screen. Once mapping is saved, this will not be seen elsewhere.
- The form_source_url field is always included and contains the URL from which the form was filled as provided by Gravity Forms. If you do not want to record this, skip mapping it.
- Changing native form or Gravity Form information will require remapping. For example, if you change the label on a field of your Gravity Form after mapping, you will need to reset the mapping and remap the form using the new field name.
- If multiple fields on your form have the same label, all subsequent copies after the first will have a number following the field name. For example, the second copy will have 0 following the field name, followed by 1 on the third, and so on. This can include hidden fields, and this ensures that your data comes through if there is a hidden field with the same name.
- Field names will show only the first 24 characters when mapping. This helps to prevent issues with Gravity Forms fields that have lengthy names.
- Fields on your form must have labels in order to be collected by Lead Gen & CRM. If you do not want fields to have visible labels, mark field labels as hidden within Gravity Forms.
- Plugins may prevent collection. Lead Gen & CRM may not be able to collect special fields added to Gravity Forms via additional plugins. Some plugins may prevent form collection entirely as well.