Question

I am trying to let a contact form (Contact Form 7) on a WordPress site create new contacts in my CRM program (solve360). To make it easier, I also activated a plugin (Forms: 3rd Party Integration) in which I defined a submission url and field mapping. Part of it works, but I am missing something simple here...

When pressing the send button, the data is sent to an email address (success) and to solve360 (not yet successfully). I actually receive a message that a new contact was created in solve360, however all the fields are empty. So I am guessing the problem is that the form fields are not properly transferred to the solve360 fields. However, I am using this template from solve360:

 // REQUIRED Edit with the email address you login to Solve360 with
 define('USER', '****************');
 // REQUIRED Edit with token, Solve360 menu > My Account > API Reference > API Token
 define('TOKEN', '*****************');

 // Get request data
 $requestData = array();
 parse_str($_SERVER['QUERY_STRING'], $requestData);

 // Configure service gateway object
 require 'Solve360Service.php';
 $solve360Service = new Solve360Service(USER, TOKEN);

 //
 // Preparing the contact data
 //
 $contactFields =      array('firstname','lastname','businessemail','businessphonedirect','name','homeaddress','cus     tom10641628','custom11746174','custom13346238');
 $contactData = array();
 // adding not empty fields
 foreach ($contactFields as $solve360FieldName => $requestFieldName) {
if ($requestData[$requestFieldName]) {
    $contactData[$solve360FieldName] = $requestData[$requestFieldName];
}
 }

 //
 // Saving the contact
 //
 // If there was business email provided:
 // check if the contact already exists by searching for a matching email address.
 // if a match is found update the existing contact, otherwise create a new one.
 //
 if ($contactData['businessemail']) {
$contacts = $solve360Service->searchContacts(array(
    'filtermode' => 'byemail',
    'filtervalue' => $contactData['businessemail'],
));
 }
 if (isset($contacts) && (integer)$contacts->count > 0) {
     $contactId = (integer)current($contacts->children())->id;
     $contactName = (string)current($contacts->children())->name;
     $contact = $solve360Service->editContact($contactId, $contactData);
 } else {
     $contact = $solve360Service->addContact($contactData);
     $contactName = (string)$contact->item->name;
     $contactId = (integer)$contact->item->id;
 }

 if (isset($contact->errors)) {
     // Email the error
     mail(
         USER,
         'Error while adding contact to Solve360',
         'Error: ' . $contact->errors->asXml()
     );
     die ('System error');
 } else {
// Email the result
     mail(
    USER,
    'Contact posted to Solve360',
    'Contact "' . $contactName . '" https://secure.solve360.com/contact/' . $contactId .      ' was posted to Solve360'
);
 }

In their example, they use a contact form with method="get" instead of method="post", however in the user interface of Contact Form 7, I believe the method is fixed to "post". Could this be the problem?

Or is there a different issue? Note that an empty contact is created at the moment. I can provide field mapping details and Forms 3rd party integration does allow hooks, if that helps in anyway.

Any help would be really appreciated! Thanks.

Was it helpful?

Solution

I discovered that the action method (POST) of the 3rd party plugin was not matching the expected action method (GET) of the Solve360 script. Therefore, I had to remove the following from the script:

// Get request data
$requestData = array();
parse_str($_SERVER['QUERY_STRING'], $requestData);

and change the following piece of code from

// adding not empty fields
foreach ($contactFields as $solve360FieldName => $requestFieldName) {
    if ($requestData[$requestFieldName]) {
         $contactData[$solve360FieldName] = $requestData[$requestFieldName];
    }
}

to

 // adding not empty fields
 foreach ($contactFields as $solve360FieldName => $requestFieldName) {
     if ($_POST[$requestFieldName]) {
         $contactData[$solve360FieldName] = $_POST[$requestFieldName];
     }
 }

Hope this will help someone who is connecting Contact Form 7 to their Solve360 database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top