Complete Guide to Integrating Gravity Forms with SendSquared
This guide provides a comprehensive approach to integrating WordPress Gravity Forms with SendSquared, covering both basic contact integration and advanced lead management integration.
Table of Contents
- Overview
- Prerequisites
- Basic Contact Integration
- Advanced Lead with Contact Integration
- Troubleshooting
- Support Resources
Overview
SendSquared offers two primary integration options with Gravity Forms:
- Basic Contact Integration: Simple integration that sends contact information to SendSquared when a form is submitted.
- Advanced Lead with Contact Integration: More comprehensive integration that creates both a contact record and a lead record in SendSquared's CRM.
Choose the integration type based on your specific business needs.
Prerequisites
Before implementing either integration, ensure you have:
- WordPress with Gravity Forms plugin installed and activated
- Admin access to both WordPress and SendSquared
- Basic knowledge of PHP or access to a developer
- Access to edit your theme's
functions.php
file or ability to create a custom plugin
Basic Contact Integration
The basic integration sends form submissions to SendSquared to add contacts to your email list.
Basic Implementation Steps
- Copy the code snippet below
- Paste it into your theme's
functions.php
file or in a custom plugin - Replace
your-email-from-a-form-here
with the field ID of your email field - Replace
your-name-from-a-form-here
with the field ID of your name field - Replace
your-send-squared-token
with your actual SendSquared token - Replace
123
with the ID of your Gravity Form - Test your form submission
Basic Code Explanation
<?php
add_action( "gform_after_submission", "post_to_send_squared", 10, 2 );
function post_to_send_squared( $entry, $form ) {
// Only proceed if the form ID is 123
if ( $form['id'] != 123 ) {
return;
}
// API token
$token = "your-send-squared-token";
// Form data
$email = rgar( $entry, "your-email-from-a-form-here" );
$name = rgar( $entry, "your-name-from-a-form-here" );
// API URL
$api_url = "https://app-api.sendsquared.com/v1/pub/popup?token=" . $token;
// API data
$api_data = [
"email" => $email,
"name" => $name
];
// Send the data to the API
$response = wp_remote_post( $api_url, [ "body" => $api_data ] );
// Check the response status
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
error_log( "Error submitting form to SendSquared: " . print_r( $response, true ) );
}
}
The code hooks into Gravity Forms' gform_after_submission
action, which triggers after a form is submitted. It checks if the form ID matches your specified form, then collects the form data and sends it to SendSquared's API.
Basic Additional Customization
You can modify the code to include additional fields:
// Example of adding additional fields
$api_data = [
"email" => $email,
"name" => $name,
"phone" => rgar( $entry, "your-phone-field-id" ),
"-custom_field_1" => rgar( $entry, "your-custom-field-1-id" ),
"-custom_field_2" => rgar( $entry, "your-custom-field-2-id" )
];
Make sure any additional fields you add are supported by the SendSquared API.
Advanced Lead with Contact Integration
The advanced integration creates both a contact record and a lead record in SendSquared's CRM from a single form submission.
Implementation Checklist
- Gravity Forms: Identify your form ID
- Gravity Forms: Identify your email field ID
- Gravity Forms: Identify your first name field ID
- Gravity Forms: Identify your last name field ID
- Gravity Forms: Identify your phone field ID
- Gravity Forms: Identify your interest field ID
- Gravity Forms: Identify your notes field ID
- SendSquared: Obtain your API key
- SendSquared: Determine the lead type ID to use
- SendSquared: Determine the lead status ID to use
- SendSquared: Identify the user ID for lead assignment
- SendSquared: Determine the source ID (if applicable)
- Test the integration after implementation
Gathering Required Information
From Gravity Forms:
- Form ID: Go to Forms > All Forms in WordPress admin and note the ID number
- Field IDs: Navigate to the form editor and hover over each field to see its ID:
- Email field ID
- First name field ID
- Last name field ID
- Phone field ID
- Interest field ID
- Notes/comments field ID
- Any other fields you want to capture
From SendSquared:
- API Key: Go to Settings > API Keys in SendSquared admin panel
- Lead Type ID: Navigate to Settings > Lead Types
- Lead Status ID: Go to Settings > Lead Statuses
- User ID: Found in the Users section
- Source ID: If tracking lead sources, found in Settings > Sources
Advanced Implementation Steps
- Copy the code snippet below
- Paste it into your theme's
functions.php
file or in a custom plugin - Update the form ID with your actual Gravity Form ID
- Update all field IDs to match your form fields
- Update the SendSquared specific IDs:
lead_type_id
lead_status_id
user_id
source_id
- Replace
your-api-key-here
with your actual SendSquared API key - Test your form submission
Advanced Code Explanation
<?php
add_action("gform_after_submission", "post_to_send_squared_lead_form", 10, 2);
function post_to_send_squared_lead_form($entry, $form)
{
// Update the form ID to match your lead form
if ($form['id'] != 123) {
return;
}
// Update these field IDs with your actual Gravity Forms field IDs
$email = rgar($entry, "your-email-field-id");
$first_name = rgar($entry, "your-first-name-field-id");
$last_name = rgar($entry, "your-last-name-field-id");
$phone = rgar($entry, "your-phone-field-id"); // must be in E.164 format
$interest_in = rgar($entry, "your-interest-field-id");
$other_items = rgar($entry, "your-notes-field-id");
// This constructs the subject line using the interest field
$subject = 'Interested in ' . $interest_in;
$now = new DateTime();
$formatted_now = $now->format(DateTime::ATOM);
// Contact data structure
$contactData = array(
'email' => $email,
'first_name' => $first_name,
'last_name' => $last_name,
'mobile_phone' => $phone, // must be in E.164 format (+1XXXXXXXXXX)
);
// Lead data structure
$leadData = array(
// Update these IDs with your actual SendSquared IDs
'lead_type_id' => 116, // Update with your lead type ID
'lead_status_id' => 504, // Update with your lead status ID
'subject' => $subject,
'interest_start_at' => $formatted_now,
'interest_end_at' => $formatted_now,
'quantity_1' => 1, // Number of adults - customize as needed
'quantity_2' => 0, // Number of children - customize as needed
'notes' => array($other_items),
'user_id' => 1446, // Update with your agent user ID
'source_id' => 0, // Update with your source ID if needed
);
// Prepare request data
$requestData = json_encode(array(
'contact' => $contactData,
'lead' => $leadData,
));
// Send data to the SendSquared API
$response = wp_remote_post('https://api.sendsquared.com/v1/leads/lead-with-contact', array(
'method' => 'POST',
'headers' => array(
'Content-Type' => 'application/json',
// Update with your actual API key
'x-api-key' => 'your-api-key-here',
),
'body' => $requestData,
));
// Error handling
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) != 200) {
$response_code = wp_remote_retrieve_response_code($response);
$response_body = wp_remote_retrieve_body($response);
error_log("Error submitting lead to SendSquared (Code: {$response_code}): " . $response_body);
}
}
This code also hooks into the gform_after_submission
action but creates both a contact and a lead record in SendSquared.
Understanding the rgar() Function
The rgar()
function retrieves values from form entries:
- Simple fields (text, email, etc.):
rgar($entry, "field_id")
- Name fields: First name is
.3
, last name is.6
- Address fields: Street is
.1
, city is.3
, state is.4
, zip is.5
Example:
// Get the value for field ID 3
$email = rgar($entry, "3");
// Get the value for a specific input in a complex field
$first_name = rgar($entry, "14.3");
Understanding the Lead with Contact API
The SendSquared Lead With Contact API creates both a contact record and a lead record in a single API call, linking them together automatically. This is useful when:
- You want to capture new leads from your website
- You need to track interest in specific properties or services
- You want to automate the lead capture process
Customizing the Lead Data
You can customize various aspects of the lead data:
// Example of additional lead customization
$leadData = array(
'lead_type_id' => 116,
'lead_status_id' => 504,
'subject' => $subject,
'interest_start_at' => $formatted_now,
'interest_end_at' => $formatted_now,
'quantity_1' => intval(rgar($entry, "your-adults-field-id")), // Get adults count from form
'quantity_2' => intval(rgar($entry, "your-children-field-id")), // Get children count from form
'notes' => array(
"Interest: " . $interest_in,
"Budget: " . rgar($entry, "your-budget-field-id"),
"Additional notes: " . $other_items
),
'user_id' => 1446, // The agent who will handle this lead
'source_id' => 123, // Your website source ID
);
Troubleshooting
If your integration isn't working properly, check these common issues:
- Field ID Mismatch: Verify that your Gravity Forms field IDs match exactly what you've specified in the code
- API Credentials: Confirm that your SendSquared token or API key is correct
- Error Logs: Check your WordPress error logs for any API errors
- Response Codes: Pay attention to response codes from the SendSquared API:
- 422 Error: This means validation failed. Check field formats (especially phone numbers) and required fields.
- Network Issues: Ensure that WordPress can make outgoing HTTP requests (some hosting providers block these)
- API Accessibility: Verify that the SendSquared API endpoint is accessible from your server
For debugging API responses, modify the error logging to include the response body:
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) != 200) {
$response_code = wp_remote_retrieve_response_code($response);
$response_body = wp_remote_retrieve_body($response);
error_log("Error submitting to SendSquared (Code: {$response_code}): " . $response_body);
}
Support Resources
For additional support, contact SendSquared support at:
- Email: support@sendsquared.com
- Phone: +1.855.340.7363
For Gravity Forms support, refer to their documentation at: