Wordpress:将CRM(solve360)与Contact Form 7集成

时间:2014-04-10 21:59:49

标签: php wordpress forms contact

我试图让WordPress网站上的联系表格(联系表格7)在我的CRM程序中创建新联系人(solve360)。为了更容易,我还激活了一个插件(表单:第三方集成),我在其中定义了提交URL和字段映射。部分工作,但我在这里缺少一些简单的东西......

按下发送按钮时,数据将被发送到电子邮件地址(成功)并解决360(尚未成功)。我实际收到一条消息,说明在solve360中创建了一个新的联系人,但所有字段都是空的。所以我猜测问题是表单字段没有正确地转移到solve360字段。但是,我正在使用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'
);
 }

在他们的示例中,他们使用的方法是使用method =“get”而不是method =“post”,但是在Contact Form 7的用户界面中,我认为该方法固定为“post”。这可能是问题吗?

或者是否有其他问题?请注意,此时会创建一个空联系人。我可以提供字段映射详细信息,而表单第三方集成确实允许挂钩,如果这有用的话。

任何帮助都会非常感激!感谢。

1 个答案:

答案 0 :(得分:1)

我发现第三方插件的操作方法(POST)与Solve360脚本的预期操作方法(GET)不匹配。因此,我不得不从脚本中删除以下内容:

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

并从

更改以下代码
// adding not empty fields
foreach ($contactFields as $solve360FieldName => $requestFieldName) {
    if ($requestData[$requestFieldName]) {
         $contactData[$solve360FieldName] = $requestData[$requestFieldName];
    }
}

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

希望这可以帮助将Contact Form 7连接到他们的Solve360数据库的人。