Contact Form 7 is one of the most popular form plugins for WordPress. Lead Gen & CRM can only integrate with Contact Form 7 4.8 or greater.
If you are using a previous version, upgrade to the latest version of Contact Form 7 prior to integrating with Lead Gen & CRM.
This article details how to integrate a Contact Form 7 form into Lead Gen & CRM with .PHP.
Administrators | ✓ | |
Company Managers | ✓ | |
Marketing Managers | ✓ | |
Sales Managers | ||
Salespersons | ||
Jr. Salespersons |
This article will detail a method to connect Contact Form 7 forms using .PHP code. When using this method, the Native Form code should not be on the page with the form, as it will all be done from the .PHP code.
If Native Form embed code was previously placed for the form, it must be removed.
The .PHP detailed here can be added to your functions.php file in Wordpress. Some themes may ask you to place your custom code elsewhere in another .PHP file.
While you can place it there, be sure to test it directly from functions.php if there are any issues, as compatibility in other files may vary based on your Wordpress theme or other plugins.
Some Wordpress themes may hide access to the functions.php file. The functions.php file can also be accessed using FTP. Contact your website administrator if you do not see the functions.php file.
Additionally, FTP access is recommended in case the functions.php file needs to be reverted, as incorrect code here can make the site inaccessible except from FTP. Pay close attention to the code that you add to functions.php. If you add incorrect code, you may be locked out of your Wordpress account.
Create a backup of your current functions.php before making these changes and be prepared to replace it via FTP if needed.
Before you can begin integrating Contact Form 7 with Lead Gen & CRM, you will need to obtain certain form information.
To obtain the necessary form information, create or edit a native form.
Review the generated JavaScript embed code in the window that appears.
Keep this browser tab open.
Once the Native Form is created, it will display a block of code. The code is different for every created Native Form. The displayed code is similar to the following example:
<script type="text/javascript"> var __ss_noform = __ss_noform || []; __ss_noform.push(['baseURI', 'https://app-XXXXXXXXXX.marketingautomation.services/webforms/receivePostback/MzYwN7EwMzcyAgA/']); __ss_noform.push(['endpoint', '30e3bbfe-a5e7-4207-9237-e9f9e2ff80e9']) </script> <script type="text/javascript" src="https://koi-XXXXXXXXXX.marketingautomation.services/client/noform.js?ver=1.24" ></script>
Before doing anything specific to your form, you will need to make modifications to your functions.php file in Wordpress.
To modify the functions.php file, do the following:
function submitToSharpSpring($data, $baseURI, $endPoint) {
$params = '';
foreach($data as $key => $value) {
if(!is_array($value)) {
$params = $params . $key . '=' . urlencode($value) . "&";
}
else {
$params = $params . $key . '=' . urlencode(implode(',',$value)) . "&";
}
}
if (isset($_COOKIE['__ss_tk'])) {
$trackingid__sb = $_COOKIE['__ss_tk'];
$params = $params . "trackingid__sb=" . urlencode($trackingid__sb);
}
// Prepare URL
$ssRequest = $baseURI . $endPoint . "/jsonp/?" . $params;
// Send request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ssRequest);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
ob_start();
var_dump($data);
$data_dump = ob_get_clean();
curl_close($ch);
}
add_action( 'wpcf7_before_send_mail', function ($cf7) { // Your unique code for each form goes here });
Paste the following code below the line that contains Your unique code for each form goes here
and above the closing });
line:
if ($_POST['_wpcf7'] == Your Form ID){ $baseURI = 'your baseURI'; $endpoint = 'your endpoint'; submitToSharpSpring($_POST, $baseURI, $endpoint); } // If connecting another form, place its code below this one
To add additional forms, repeat Step 6 above. When doing so, add each code block below the end of the above code before it. The code should be added just under the comment that says:
// If connecting another form, place its code below this one
Be aware that your baseURI
will typically be the same for all forms within an instance of Lead Gen & CRM.
Once the functions.php file has been modified, you can begin adding unique code to individual forms.
This only needs to be done once for each unique Contact Form 7 form, regardless of how many pages it exists on.
To add unique code to forms, do the following:
baseURI
.https://app-XXXXXXXXXX.marketingautomation.services/webforms/receivePostback/MzYwN7EwMzcyAgA/
your baseURI
with the copied baseURI
web address. It should remain in single quotes.endpoint
.30e3bbfe-a5e7-4207-9237-e9f9e2ff80e9
endpoint
value with the copied endpoint
value. It should remain in single quotes.Form ID
value within the Contact Form 7 Short Code.Form ID
value is 533
:
[contact-form-7 id="533" title="php cf7 test"]
Your Form ID
with the Form ID
number within the Contact Form 7 Short Code in the if ($_POST
line. It should not be in quotes.Below is an example of completed code that connects two Contact Form 7 forms. The first part of the code is based on the example tracking code shown above. The second part of the code would connect a form with a Form ID
of 789
in Contact Form 7 while using values from a different code.
function submitToSharpSpring($data, $baseURI, $endPoint, $track = true) {
unset($data['_wpcf7']);
unset($data['_wpcf7_version']);
unset($data['_wpcf7_locale']);
unset($data['_wpcf7_unit_tag']);
unset($data['_wpcf7_container_post']);
$params = '';
foreach($data as $key => $value) {
if(!is_array($value)) {
$params = $params . $key . '=' . urlencode($value) . "&";
}
else {
$params = $params . $key . '=' . urlencode(implode(',',$value)) . "&";
}
}
if (isset($_COOKIE['__ss_tk'])) {
$trackingid__sb = $_COOKIE['__ss_tk'];
$params = $params . "trackingid__sb=" . urlencode($trackingid__sb);
}
$sharpReq = $baseURI . $endPoint . "/jsonp/?" . $params;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $sharpReq);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
ob_start();
var_dump($data);
$data_dump = ob_get_clean();
curl_close($ch);
}
add_action( 'wpcf7_before_send_mail', function ($cf7) {
$baseURI = 'https://app-XXXXXXXXXX.marketingautomation.services/webforms/receivePostback/MzYwN7EwMzcyAgA/';
if ($_POST['_wpcf7'] == 533) {
$baseURI = 'your base URI';
$endpoint = '30e3bbfe-a5e7-4207-9237-e9f9e2ff80e9';
submitToSharpSpring($_POST, $baseURI, $endpoint);
}
// If connecting another form, place its code below this one
if ($_POST['_wpcf7'] == 789) {
$baseURI = 'https://app-XXXXXXXXXX.marketingautomation.services/webforms/receivePostback/MzYwN7EwMzcyAgA/';
$endpoint = '1234567-a5e7-bfe3-abcd-a956ae605b';
submitToSharpSpring($_POST, $baseURI, $endpoint);
}
// If connecting another form, place its code below this one
});
Copyright © 2025 · All Rights Reserved · Constant Contact · Privacy Center