Complete Guide to Integrating Contact Form 7 with SendSquared
This guide provides a comprehensive approach to integrating WordPress Contact Form 7 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 Contact Form 7:
- 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 Contact Form 7 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
with the name of your email field in Contact Form 7 - Replace
your-name
with the name of your name field in Contact Form 7 - Replace
your-list-group-uuid
with your actual SendSquared list group UUID - Test your form submission to ensure data is being sent to SendSquared
Basic Code Explanation
<?php
add_action( 'wpcf7_mail_sent', 'custom_form_submission' );
function custom_form_submission( $contact_form ) {
// Get the form data
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$email = $posted_data['your-email'];
$name = $posted_data['your-name'];
}
// Set the API URL with the token
$token = "your-list-group-uuid";
$api_url = "https://app-api.sendsquared.com/v1/pub/popup?token=$token";
// Set up the API data
$api_data = array(
"email" => $email,
"name" => $name,
);
// Use wp_remote_post to send the data to the API
$response = wp_remote_post( $api_url, array(
"body" => $api_data
) );
// Check the response code
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
// Log an error
error_log( "Error submitting form: " . print_r( $response, true ) );
}
}
The code hooks into Contact Form 7's wpcf7_mail_sent
action, which is triggered after a form is submitted and the confirmation email is sent. It collects the form data, sets up the API data, and uses wp_remote_post
to send the data to the API.
Basic Additional Customization
You can modify this code to include additional fields from your Contact Form 7 form:
// Example of adding additional fields
$api_data = array(
"email" => $email,
"name" => $name,
"phone" => $posted_data['your-phone'],
"company" => $posted_data['your-company'],
"custom_field" => $posted_data['your-custom-field']
);
Make sure that 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
Copy this checklist to your task management system to track your progress:
- Contact Form 7: Create your lead capture form
- Contact Form 7: Note your form field names
- Contact Form 7: Test that your form works properly
- 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 Contact Form 7:
- Form Field Names: When creating your Contact Form 7 form, you need to use these naming conventions for your form fields:
- Email field: Use a field name like
your-email
- First name field: Use a field name like
your-first-name
- Last name field: Use a field name like
your-last-name
- Phone field: Use a field name like
your-phone
- Interest field: Use a field name like
your-interest
- Message/notes field: Use a field name like
your-message
- Email field: Use a field name like
Example Contact Form 7 form code:
<label>First Name
[text* your-first-name] </label>
<label>Last Name
[text* your-last-name] </label>
<label>Email
[email* your-email] </label>
<label>Phone
[tel* your-phone placeholder "+1XXXXXXXXXX"] </label>
<label>Interest
[select your-interest "Property Rental" "Property Purchase" "Property Management" "Other"] </label>
<label>Message
[textarea your-message] </label>
[submit "Send"]
From SendSquared:
- API Key: Go to Settings > API Keys in your SendSquared admin panel to obtain your API key
- Lead Type ID: Navigate to Settings > Lead Types and note the ID of the appropriate lead type
- Lead Status ID: Go to Settings > Lead Statuses and identify the status ID you want to use for new leads
- User ID: This is the ID of the agent who will be assigned these leads. You can find user IDs in the Users section
- Source ID: If you track lead sources in SendSquared, obtain the appropriate source ID from Settings > Sources
All of these IDs are required for the integration to work properly. If you're unsure about any of these values, contact SendSquared support for assistance in locating them in your account.
Advanced Implementation Steps
- Copy the code snippet below
- Paste it into your theme's
functions.php
file or in a custom plugin - Update all the field names to match your Contact Form 7 field names:
your-email
your-first-name
your-last-name
your-phone
your-interest
your-message
- Update the SendSquared specific IDs that you gathered earlier:
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 to ensure leads are being created in SendSquared
Advanced Code Explanation
<?php
add_action('wpcf7_mail_sent', 'send_cf7_data_to_sendsquared');
function send_cf7_data_to_sendsquared($contact_form)
{
// Get the form submission data
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$posted_data = $submission->get_posted_data();
// Get the form field values - update these field names with your actual CF7 field names
$email = isset($posted_data['your-email']) ? $posted_data['your-email'] : '';
$first_name = isset($posted_data['your-first-name']) ? $posted_data['your-first-name'] : '';
$last_name = isset($posted_data['your-last-name']) ? $posted_data['your-last-name'] : '';
$phone = isset($posted_data['your-phone']) ? $posted_data['your-phone'] : ''; // must be in E.164 format
$interest_in = isset($posted_data['your-interest']) ? $posted_data['your-interest'] : '';
$other_items = isset($posted_data['your-message']) ? $posted_data['your-message'] : '';
// 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);
}
}
}
Understanding Contact Form 7 Field Data
The integration uses the wpcf7_mail_sent
hook which is triggered after a form is successfully submitted and the confirmation email is sent. Contact Form 7 structures the submitted data as an associative array where the keys are the field names defined in your form.
Basic usage:
// Get the submission instance
$submission = WPCF7_Submission::get_instance();
$posted_data = $submission->get_posted_data();
// Access field values by field name
$email = $posted_data['your-email'];
$name = $posted_data['your-name'];
When working with different field types:
- Text, email, and other simple fields:
$posted_data['field-name']
- Checkboxes (multiple selections):
$posted_data['checkbox-field-name']
(returns an array) - File uploads: Use
$submission->uploaded_files()
instead
Always use the isset() check to avoid PHP errors if a field doesn't exist or wasn't filled out.
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 to fit your specific needs:
// 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' => isset($posted_data['adults']) ? intval($posted_data['adults']) : 1,
'quantity_2' => isset($posted_data['children']) ? intval($posted_data['children']) : 0,
'notes' => array(
"Interest: " . $interest_in,
"Budget: " . (isset($posted_data['budget']) ? $posted_data['budget'] : ''),
"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 Name Mismatch: Verify that your Contact Form 7 field names 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. The response body will contain details about what is missing or incorrect in your request. Check field formats (especially the phone number which must be in E.164 format) 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
To debug Contact Form 7 submissions, you can add this code temporarily to see the structure of your form data:
add_action('wpcf7_mail_sent', 'debug_cf7_submission');
function debug_cf7_submission($contact_form) {
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$posted_data = $submission->get_posted_data();
error_log('CF7 Submission: ' . print_r($posted_data, true));
}
}
Support Resources
For additional support, contact SendSquared support at:
- Email: support@sendsquared.com
- Phone: +1.855.340.7363
For Contact Form 7 support, refer to their documentation at: