-
Notifications
You must be signed in to change notification settings - Fork 0
/
webform_salesforce.module
42 lines (39 loc) · 1.68 KB
/
webform_salesforce.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Implements hook_webform_submission_presave().
*/
function webform_salesforce_webform_submission_presave($node, &$submission) {
switch ($node->nid) {
case YOUR_NID: // the node ID of your Webform
$sfid = 'YOUR_SALESFORCE_ID'; // Your Salesforce ID
// Bundle the request and send it to Salesforce.com
// Edit the below and enter the CID values for each field
$req .= '&first_name=' . urlencode($submission->data[FIELD_CID]['value'][0]);
$req .= '&last_name=' . urlencode($submission->data[FIELD_CID]['value'][0]);
$req .= '&title=' . urlencode($submission->data[FIELD_CID]['value'][0]);
$req .= '&company=' . urlencode($submission->data[FIELD_CID]['value'][0]);
$req .= '&email=' . urlencode($submission->data[FIELD_CID]['value'][0]);
$req .= '&city=' . urlencode($submission->data[FIELD_CID]['value'][0]);
$req .= '&debug=' . urlencode('0'); // change to 1 for debug mode
$req .= '&oid=' . urlencode($sfid);
$req .= '&retURL=' . urlencode('http://www.example.com');
// $req .= '&debugEmail=' . urlencode('[email protected]');
$header = 'POST /servlet/servlet.WebToLead?encoding=UTF-8 HTTP/1.0\r\n';
$header .= 'Content-Type: application/x-www-form-urlencoded\r\n';
$header .= 'Host: www.salesforce.com\r\n';
$header .= 'Content-Length: ' . drupal_strlen($req) . '\r\n\r\n';
$fp = fsockopen('www.salesforce.com', 80, $errno, $errstr, 30);
if (!$fp) {
echo 'No connection made';
}
else {
fwrite($fp, $header . $req);
while (!feof($fp)) {
$res = fgets($fp, 1024);
echo $res;
}
}
fclose($fp);
break;
}
}