teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

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

2019/07/10 07:02

投稿

scissorhands
scissorhands

スコア13

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,7 @@
1
1
  ### 前提・実現したいこと
2
-
3
- ここに質問の内容を詳しく書いてください。
4
2
  contactform7で作成したフォームとsalesforceを連携させたい
3
+ (参考url)
4
+ https://qiita.com/emegane/items/957c5db4e41d11454430
5
5
 
6
6
  ### 発生している問題・エラーメッセージ
7
7
  function.php、contactform7に必要だと思われる処理をいれてもsalesforceに反映されません。
@@ -55,6 +55,4 @@
55
55
  return $cf7;
56
56
  }
57
57
  add_action('wpcf7_before_send_mail', 'sf_web_to_lead');
58
- ?>
58
+ ?>
59
- (参考url)
60
- https://qiita.com/emegane/items/957c5db4e41d11454430

2

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

2019/07/10 07:02

投稿

scissorhands
scissorhands

スコア13

title CHANGED
File without changes
body CHANGED
@@ -12,51 +12,49 @@
12
12
 
13
13
  function.phpにいれた内容はこのような感じです。
14
14
  <?php
15
- add_filter( 'wpcf7_before_send_mail*', 'de_wpcf7_salesforce' );
16
-
17
- function de_wpcf7_salesforce( $contact_form ) {
15
+ function sf_web_to_lead($cf7)
16
+ {
18
- global $wpdb;
17
+ // 送信されるデータを取得します。
19
-
20
- if ( ! isset( $contact_form->posted_data ) && class_exists( 'WPCF7_Submission' ) ) {
21
- $submission = WPCF7_Submission::get_instance();
18
+ $submission = WPCF7_Submission::get_instance();
22
-
19
+ // POSTするクエリを用意します。
23
- if ( $submission ) {
20
+ $query_data = array();
24
- $form_data = $submission->get_posted_data();
21
+ foreach ($posted_data as $name => $value) {
22
+ // Contact form 7用のパラメータはスキップします。
23
+ if (0 === strpos($name, '_wpcf7')) {
24
+ continue;
25
25
  }
26
+ // sf-からはじまるパラメータは、先頭のPrefixを削除します。
27
+ if (0 === strpos($name, 'sf-')) {
28
+ $name = substr($name, 3);
29
+ }
30
+ // 複数選択可能なフィールド(select[multiple]やcheckboxなど)の場合は、
31
+ // hoge=value1&hoge=value2のように送信します。(Salesforceの仕様)
32
+ if (is_array($value)) {
33
+ foreach ($value as $option_value) {
34
+ $query_data[] = sprintf('%s=%s', $name, $option_value);
35
+ }
26
- } else {
36
+ } else {
27
- return $contact_form;
37
+ $query_data[] = sprintf('%s=%s', $name, $value);
38
+ }
28
39
  }
40
+ $query = implode('&', $query_data);
29
41
 
42
+ // Init cURL session
30
- $body = array(
43
+ $ch = curl_init();
31
- 'orgid' => '00D10000000ZsZkEAK',
44
+ if ('' !== curl_error($ch)) {
32
- 'recordType' => 'XXXXXXXXXXXXXXX',
45
+ // Error handling
46
+ } else {
33
- 'retURL' => 'http://recruit.hairbook.jp/recruit-thanks',
47
+ $sf_url = 'https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
34
- 'sf-00N5F000006xynF' => $form_data['sf-00N5F000006xynF'],
35
- 'sf-00N5F000006xyWd' => $form_data['sf-00N5F000006xyWd'],
36
- 'sf-00N5F000006xyWi' => $form_data['sf-00N5F000006xyWi'],
37
- 'sf-00N5F000006xyWn' => $form_data['sf-00N5F000006xyWn'],
38
- 'company' => $form_data['company'],
39
- 'first_name' => $form_data['first_name'],
40
- 'last_name' => $form_data['last_name'],
41
- 'sf-00N100000059GEB' => $form_data['sf-00N100000059GEB'],
42
- 'state' => $form_data['state'],
43
- 'phone' => $form_data['phone'],
44
- 'email' => $form_data['email'],
45
- 'sf-00N5F000006p0Sk' => $form_data['sf-00N5F000006p0Sk'],
46
- 'sf-00N5F000006xz04' => $form_data['sf-00N5F000006xz04'],
47
- );
48
48
 
49
- $url = 'https://webto.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8';
50
-
51
- $params = array(
49
+ curl_setopt($ch, CURLOPT_URL, $sf_url);
52
- 'headers' => array(
50
+ curl_setopt($ch, CURLOPT_POST, 1);
53
- 'Content-Type' => 'application/x-www-form-urlencoded'
54
- ),
55
- 'body' => $body
56
- );
57
-
58
- $response = wp_remote_post( $url, $params );
51
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
52
+ curl_exec($ch);
53
+ curl_close($ch);
54
+ }
55
+ return $cf7;
59
56
  }
57
+ add_action('wpcf7_before_send_mail', 'sf_web_to_lead');
60
58
  ?>
61
59
  (参考url)
62
60
  https://qiita.com/emegane/items/957c5db4e41d11454430

1

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

2019/07/10 04:49

投稿

scissorhands
scissorhands

スコア13

title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,7 @@
8
8
  反映されない原因の一つとしてformactionの部分がsalesforceに送られるように変更されていないように見えます。
9
9
  ソースコードで見たところ、下のようになっていました。
10
10
  ```
11
- <form action="/salonjobs/job/%e9%8a%80%e5%ba%a7labo#wpcf7-f918-o1" method="post" class="wpcf7-form" novalidate="novalidate">```
11
+ <form action="/サイトurl/%e9%8a%80%e5%ba%a7labo#wpcf7-f918-o1" method="post" class="wpcf7-form" novalidate="novalidate">```
12
12
 
13
13
  function.phpにいれた内容はこのような感じです。
14
14
  <?php