質問編集履歴

3

質問がわかりにくいと感じたため

2019/07/10 07:02

投稿

scissorhands
scissorhands

スコア13

test CHANGED
File without changes
test CHANGED
@@ -1,10 +1,10 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
+ contactform7で作成したフォームとsalesforceを連携させたい
3
4
 
5
+ (参考url)
4
6
 
5
- ここに質問の内容を詳しく書いてください。
6
-
7
- contactform7で作成したフォームとsalesforceを連携させたい
7
+ https://qiita.com/emegane/items/957c5db4e41d11454430
8
8
 
9
9
 
10
10
 
@@ -113,7 +113,3 @@
113
113
  add_action('wpcf7_before_send_mail', 'sf_web_to_lead');
114
114
 
115
115
  ?>
116
-
117
- (参考url)
118
-
119
- https://qiita.com/emegane/items/957c5db4e41d11454430

2

違う内容が入ってしまっていました。

2019/07/10 07:02

投稿

scissorhands
scissorhands

スコア13

test CHANGED
File without changes
test CHANGED
@@ -26,95 +26,91 @@
26
26
 
27
27
  <?php
28
28
 
29
+ function sf_web_to_lead($cf7)
30
+
31
+ {
32
+
33
+ // 送信されるデータを取得します。
34
+
35
+ $submission = WPCF7_Submission::get_instance();
36
+
37
+ // POSTするクエリを用意します。
38
+
39
+ $query_data = array();
40
+
41
+ foreach ($posted_data as $name => $value) {
42
+
43
+ // Contact form 7用のパラメータはスキップします。
44
+
45
+ if (0 === strpos($name, '_wpcf7')) {
46
+
47
+ continue;
48
+
49
+ }
50
+
51
+ // sf-からはじまるパラメータは、先頭のPrefixを削除します。
52
+
53
+ if (0 === strpos($name, 'sf-')) {
54
+
55
+ $name = substr($name, 3);
56
+
57
+ }
58
+
59
+ // 複数選択可能なフィールド(select[multiple]やcheckboxなど)の場合は、
60
+
29
- add_filter( 'wpcf7_before_send_mail*', 'de_wpcf7_salesforce' );
61
+ // hoge=value1&hoge=value2のように送信します。(Salesforceの仕様)
62
+
63
+ if (is_array($value)) {
64
+
65
+ foreach ($value as $option_value) {
66
+
67
+ $query_data[] = sprintf('%s=%s', $name, $option_value);
68
+
69
+ }
70
+
71
+ } else {
72
+
73
+ $query_data[] = sprintf('%s=%s', $name, $value);
74
+
75
+ }
76
+
77
+ }
78
+
79
+ $query = implode('&', $query_data);
30
80
 
31
81
 
32
82
 
33
- function de_wpcf7_salesforce( $contact_form ) {
83
+ // Init cURL session
34
84
 
35
- global $wpdb;
85
+ $ch = curl_init();
86
+
87
+ if ('' !== curl_error($ch)) {
88
+
89
+ // Error handling
90
+
91
+ } else {
92
+
93
+ $sf_url = 'https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
36
94
 
37
95
 
38
96
 
39
- if ( ! isset( $contact_form->posted_data ) && class_exists( 'WPCF7_Submission' ) ) {
97
+ curl_setopt($ch, CURLOPT_URL, $sf_url);
40
98
 
41
- $submission = WPCF7_Submission::get_instance();
99
+ curl_setopt($ch, CURLOPT_POST, 1);
42
100
 
101
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
43
102
 
103
+ curl_exec($ch);
44
104
 
45
- if ( $submission ) {
46
-
47
- $form_data = $submission->get_posted_data();
48
-
49
- }
50
-
51
- } else {
52
-
53
- return $contact_form;
105
+ curl_close($ch);
54
106
 
55
107
  }
56
108
 
57
-
58
-
59
- $body = array(
109
+ return $cf7;
60
-
61
- 'orgid' => '00D10000000ZsZkEAK',
62
-
63
- 'recordType' => 'XXXXXXXXXXXXXXX',
64
-
65
- 'retURL' => 'http://recruit.hairbook.jp/recruit-thanks',
66
-
67
- 'sf-00N5F000006xynF' => $form_data['sf-00N5F000006xynF'],
68
-
69
- 'sf-00N5F000006xyWd' => $form_data['sf-00N5F000006xyWd'],
70
-
71
- 'sf-00N5F000006xyWi' => $form_data['sf-00N5F000006xyWi'],
72
-
73
- 'sf-00N5F000006xyWn' => $form_data['sf-00N5F000006xyWn'],
74
-
75
- 'company' => $form_data['company'],
76
-
77
- 'first_name' => $form_data['first_name'],
78
-
79
- 'last_name' => $form_data['last_name'],
80
-
81
- 'sf-00N100000059GEB' => $form_data['sf-00N100000059GEB'],
82
-
83
- 'state' => $form_data['state'],
84
-
85
- 'phone' => $form_data['phone'],
86
-
87
- 'email' => $form_data['email'],
88
-
89
- 'sf-00N5F000006p0Sk' => $form_data['sf-00N5F000006p0Sk'],
90
-
91
- 'sf-00N5F000006xz04' => $form_data['sf-00N5F000006xz04'],
92
-
93
- );
94
-
95
-
96
-
97
- $url = 'https://webto.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8';
98
-
99
-
100
-
101
- $params = array(
102
-
103
- 'headers' => array(
104
-
105
- 'Content-Type' => 'application/x-www-form-urlencoded'
106
-
107
- ),
108
-
109
- 'body' => $body
110
-
111
- );
112
-
113
-
114
-
115
- $response = wp_remote_post( $url, $params );
116
110
 
117
111
  }
112
+
113
+ add_action('wpcf7_before_send_mail', 'sf_web_to_lead');
118
114
 
119
115
  ?>
120
116
 

1

サイトのurlが入っていたため、修正しました。

2019/07/10 04:49

投稿

scissorhands
scissorhands

スコア13

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  ```
20
20
 
21
- <form action="/salonjobs/job/%e9%8a%80%e5%ba%a7labo#wpcf7-f918-o1" method="post" class="wpcf7-form" novalidate="novalidate">```
21
+ <form action="/サイトurl/%e9%8a%80%e5%ba%a7labo#wpcf7-f918-o1" method="post" class="wpcf7-form" novalidate="novalidate">```
22
22
 
23
23
 
24
24