· 4 years ago · May 07, 2021, 10:56 AM
1<?php
2 /**
3 * Debug - Request in
4 */
5 echo "============Request in ============";
6 echo "<pre>";
7 print_r($_REQUEST);
8 echo "</pre>";
9
10 //API KEY HubSpot
11 $API_KEY_HUBSPOT = "95ac3c12-a144-469b-b0bd-5d789897764b" ;
12
13
14
15
16
17function SendData(string $dataForm, string $url){
18
19 $to = 'alessandro.biagini@yourbiz.it';
20 $subject = 'Mail di test';
21 $message = "Ciao, questi sono i dati della form: {$dataForm}";
22 $headers = 'From: webmaster@milestonesrl.com' . "\r\n" .
23 'Reply-To: webmaster@milestonesrl.com' . "\r\n" .
24 'X-Mailer: PHP/' . phpversion();
25
26 mail($to, $subject, $message, $headers);
27
28 // Create a new cURL resource
29 $ch = curl_init($url);
30 // Attach encoded JSON string to the POST fields
31 curl_setopt($ch, CURLOPT_POSTFIELDS, $dataForm);
32
33 // Set the content type to application/json
34 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
35
36 // Return response instead of outputting
37 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
38
39 // Execute the POST request
40 $response = curl_exec($ch); //Log the response from HubSpot as needed.
41 $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
42
43 curl_close($ch);
44 //print_r($status_code);
45 //print_r($response);
46 /**
47 * Debug - Response
48 */
49echo "============Response Debug============";
50 echo "<pre>";
51 $json_pretty = json_encode(json_decode($response), JSON_PRETTY_PRINT);
52echo $json_pretty;
53 echo "</pre>";
54}
55
56
57
58//Form 32
59if (isset($_POST['formId']) && ($_POST['formId'] == "32") ) {
60 //Contact
61 // API URL
62 $url = 'https://api.hsforms.com/submissions/v3/integration/secure/submit/9033646/de696c67-fa7a-4da0-9f49-e60a5c460ccf?hapikey='.$API_KEY_HUBSPOT;
63 // Setup request to send json via POST
64
65 //se non c'è POST, stop!
66 //Il form del cliente è setato come yes para privacy true
67 if (strtolower($_POST['privacy'][0]) == "yes") {
68 $privacy = true;
69 }else {
70 $privacy = false;
71 }
72 //Il form del cliente è setato come yes para newsletter true
73 if (strtolower($_POST['newsletter'][0]) == "yes") {
74 $newsletter = true;
75 }else {
76 $newsletter = false;
77 }
78 $data = array (
79 'fields' =>
80 array (
81 0 =>
82 array (
83 'name' => 'firstname',
84 'value' => $_POST['nome'],
85 ),
86 1 =>
87 array (
88 'name' => 'lastname',
89 'value' => ' ',
90 ),
91 2 =>
92 array (
93 'name' => 'email',
94 'value' => $_POST['email'],
95 ),
96 3 =>
97 array (
98 'name' => 'nazione__cloned_',
99 'value' => $_POST['country'][0],
100 ),
101 4 =>
102 array (
103 'name' => 'note',
104 'value' => $_POST['note'],
105 ),
106 ),
107 'legalConsentOptions' =>
108 array (
109 'consent' =>
110 array (
111 'consentToProcess' => $privacy,
112 'text' => 'I agree to allow Example Company to store and process my personal data.',
113 'communications' =>
114 array (
115 0 =>
116 array (
117 'value' => $newsletter,
118 'subscriptionTypeId' => 999,
119 'text' => 'I agree to receive marketing communications from Example Company.',
120 ),
121 ),
122 ),
123 ),
124 'context' =>
125 array(
126 'hutk' => $_POST['hubspotToken'],
127 'ipAddress' => $_POST['ipFormInput']
128 )
129 );
130 $dataForm = json_encode($data);
131
132echo "============json costruito da noi============";
133echo "<pre>";
134 $json_pretty = json_encode(json_decode($dataForm), JSON_PRETTY_PRINT);
135echo $json_pretty;
136echo "</pre>";
137 SendData($dataForm, $url);
138}
139
140
141
142
143if (isset($_POST['formId']) && ($_POST['formId'] == "3") ) {
144 //Contact
145 // API URL
146 $url = 'https://api.hsforms.com/submissions/v3/integration/secure/submit/9033646/de696c67-fa7a-4da0-9f49-e60a5c460ccf?hapikey='.$API_KEY_HUBSPOT;
147 // Setup request to send json via POST
148
149 //se non c'è POST, stop!
150 //Il form del cliente è setato come yes para privacy true
151 if (strtolower($_POST['privacy'][0]) == "yes") {
152 $privacy = true;
153 }else {
154 $privacy = false;
155 }
156 //Il form del cliente è setato come yes para newsletter true
157 if (strtolower($_POST['newsletter'][0]) == "yes") {
158 $newsletter = true;
159 }else {
160 $newsletter = false;
161 }
162 $data = array (
163 'fields' =>
164 array (
165 0 =>
166 array (
167 'name' => 'firstname',
168 'value' => $_POST['nome'],
169 ),
170 1 =>
171 array (
172 'name' => 'lastname',
173 'value' => ' ',
174 ),
175 2 =>
176 array (
177 'name' => 'email',
178 'value' => $_POST['email'],
179 ),
180 3 =>
181 array (
182 'name' => 'nazione__cloned_',
183 'value' => $_POST['country'][0],
184 ),
185 4 =>
186 array (
187 'name' => 'note',
188 'value' => $_POST['note'],
189 ),
190 ),
191 'legalConsentOptions' =>
192 array (
193 'consent' =>
194 array (
195 'consentToProcess' => $privacy,
196 'text' => 'I agree to allow Example Company to store and process my personal data.',
197 'communications' =>
198 array (
199 0 =>
200 array (
201 'value' => $newsletter,
202 'subscriptionTypeId' => 999,
203 'text' => 'I agree to receive marketing communications from Example Company.',
204 ),
205 ),
206 ),
207 ),
208 'context' =>
209 array(
210 'hutk' => $_POST['hubspotToken'],
211 'ipAddress' => $_POST['ipFormInput']
212 )
213 );
214 $dataForm = json_encode($data);
215
216echo "============json costruito da noi============";
217echo "<pre>";
218 $json_pretty = json_encode(json_decode($dataForm), JSON_PRETTY_PRINT);
219echo $json_pretty;
220echo "</pre>";
221 SendData($dataForm, $url);
222}
223
224
225if (isset($_POST['formId']) && ($_POST['formId'] == "7") ) {
226
227 // API URL
228 $url = 'https://api.hsforms.com/submissions/v3/integration/secure/submit/9033646/c4e7d660-b9dd-468b-9b4e-6724ca38f1a7?hapikey='.$API_KEY_HUBSPOT;
229
230 //se non c'è POST, stop!
231 //Il form del cliente è setato come yes para privacy true
232 if (strtolower($_POST['privacy'][0]) == "yes") {
233 $privacy = true;
234 }else {
235 $privacy = false;
236 }
237 //Il form del cliente è setato come yes para newsletter true
238 if (strtolower($_POST['newsletter'][0]) == "yes") {
239 $newsletter = true;
240 }else {
241 $newsletter = false;
242 }
243 // Setup request to send json via POST
244 $data = array (
245 'fields' =>
246 array (
247 0 =>
248 array (
249 'name' => 'firstname',
250 'value' => $_POST['name'],
251 ),
252 1 =>
253 array (
254 'name' => 'phone',
255 'value' => $_POST['phone'],
256 ),
257 2 =>
258 array (
259 'name' => 'email',
260 'value' => $_POST['email'],
261 ),
262 3 =>
263 array (
264 'name' => 'nazione__cloned_',
265 'value' => $_POST['country'][0],
266 ),
267 4 =>
268 array (
269 'name' => 'company',
270 'value' => $_POST['company'],
271 ),
272 5=>
273 array (
274 'name' => 'industry_segment___analitica',
275 'value' => implode(";",$_POST['industry']),
276 ),
277 6 =>
278 array (
279 'name' => 'application_fields',
280 'value' => implode(";",$_POST['application']),
281 ),
282 7 =>
283 array (
284 'name' => 'lastname',
285 'value' => ' - ',
286 )
287 ),
288 'legalConsentOptions' =>
289 array (
290 'consent' =>
291 array (
292 'consentToProcess' => $privacy,
293 'text' => 'I agree to allow Example Company to store and process my personal data.',
294 'communications' =>
295 array (
296 0 =>
297 array (
298 'value' => $newsletter,
299 'subscriptionTypeId' => 999,
300 'text' => 'I agree to receive marketing communications from Example Company.',
301 ),
302 ),
303 ),
304 ),
305 'context' =>
306 array(
307 'hutk' => $_POST['hubspotToken'],
308 'ipAddress' => $_POST['ipFormInput']
309 )
310 );
311
312 $dataForm = json_encode($data);
313 //echo "============json costruito da noi============";
314 //echo "<pre>";
315 //$json_pretty = json_encode(json_decode($dataForm), JSON_PRETTY_PRINT);
316 //echo $json_pretty;
317 //echo "</pre>";
318
319 SendData($dataForm, $url);
320}
321
322
323
324if (isset($_POST['formId']) && ($_POST['formId'] == "16") ) {
325
326 // API URL
327 $url = 'https://api.hsforms.com/submissions/v3/integration/secure/submit/9033646/c646f941-4c30-4d23-b51c-69053176fea9?hapikey='.$API_KEY_HUBSPOT;
328 // Setup request to send json via POST
329
330 //se non c'è POST, stop!
331 //Il form del cliente è setato come yes para privacy true
332 if (strtolower($_POST['privacy'][0]) == "yes") {
333 $privacy = true;
334 }else {
335 $privacy = false;
336 }
337 //Il form del cliente è setato come yes para newsletter true
338 if (strtolower($_POST['newsletter'][0]) == "yes") {
339 $newsletter = true;
340 }else {
341 $newsletter = false;
342 }
343 $data = array (
344 'fields' =>
345 array (
346 0 =>
347 array (
348 'name' => 'firstname',
349 'value' => $_POST['nome'],
350 ),
351 1 =>
352 array (
353 'name' => 'lastname',
354 'value' => ' ',
355 ),
356 2 =>
357 array (
358 'name' => 'email',
359 'value' => $_POST['email'],
360 ),
361 3 =>
362 array (
363 'name' => 'nazione__cloned_',
364 'value' => $_POST['country'][0],
365 ),
366 4 =>
367 array (
368 'name' => 'company',
369 'value' => $_POST['company'],
370 ),
371 5 =>
372 array (
373 'name' => 'note',
374 'value' => $_POST['note'],
375 ),
376 6 =>
377 array (
378 'name' => 'product_category',
379 'value' => implode(";",$_POST['info']),
380 ),
381 7 =>
382 array (
383 'name' => 'prodotto_utilizzato',
384 'value' => implode(";",$_POST['use']),
385 ),
386 8 =>
387 array (
388 'name' => 'application_fields',
389 'value' => implode(";",$_POST['focus']),
390 ),
391 ),
392 'legalConsentOptions' =>
393 array (
394 'consent' =>
395 array (
396 'consentToProcess' => $privacy,
397 'text' => 'I agree to allow Example Company to store and process my personal data.',
398 'communications' =>
399 array (
400 0 =>
401 array (
402 'value' => $newsletter,
403 'subscriptionTypeId' => 999,
404 'text' => 'I agree to receive marketing communications from Example Company.',
405 ),
406 ),
407 ),
408 ),
409 'context' =>
410 array(
411 'hutk' => $_POST['hubspotToken'],
412 'ipAddress' => $_POST['ipFormInput']
413 )
414 );
415 $dataForm = json_encode($data);
416
417 //echo "============json costruito da noi============";
418 //echo "<pre>";
419 //$json_pretty = json_encode(json_decode($dataForm), JSON_PRETTY_PRINT);
420 //echo $json_pretty;
421 //echo "</pre>";
422 SendData($dataForm, $url);
423}
424
425
426
427if (isset($_POST['formId']) && ($_POST['formId'] == "19") ) {
428
429 // API URL
430 $url = 'https://api.hsforms.com/submissions/v3/integration/secure/submit/9033646/5923f0ef-6b42-42f2-8ae9-edf85dabb62d?hapikey='.$API_KEY_HUBSPOT;
431
432 //se non c'è POST, stop!
433 //Il form del cliente è setato come yes para privacy true
434 if (strtolower($_POST['privacy'][0]) == "yes") {
435 $privacy = true;
436 }else {
437 $privacy = false;
438 }
439 //Il form del cliente è setato come yes para newsletter true
440 if (strtolower($_POST['newsletter'][0]) == "yes") {
441 $newsletter = true;
442 }else {
443 $newsletter = false;
444 }
445 // Setup request to send json via POST
446 $data = array (
447 'fields' =>
448 array (
449 0 =>
450 array (
451 'name' => 'firstname',
452 'value' => $_POST['name'],
453 ),
454 1 =>
455 array (
456 'name' => 'phone',
457 'value' => $_POST['phone'],
458 ),
459 2 =>
460 array (
461 'name' => 'email',
462 'value' => $_POST['email'],
463 ),
464 3 =>
465 array (
466 'name' => 'nazione__cloned_',
467 'value' => $_POST['country'][0],
468 ),
469 4 =>
470 array (
471 'name' => 'company',
472 'value' => $_POST['company'],
473 ),
474 5=>
475 array (
476 'name' => 'industry_segment___analitica',
477 'value' => implode(";",$_POST['industry']),
478 ),
479 6 =>
480 array (
481 'name' => 'application_fields',
482 'value' => implode(";",$_POST['application']),
483 ),
484 7 =>
485 array (
486 'name' => 'lastname',
487 'value' => ' - ',
488 )
489 ),
490 'legalConsentOptions' =>
491 array (
492 'consent' =>
493 array (
494 'consentToProcess' => $privacy,
495 'text' => 'I agree to allow Example Company to store and process my personal data.',
496 'communications' =>
497 array (
498 0 =>
499 array (
500 'value' => $newsletter,
501 'subscriptionTypeId' => 999,
502 'text' => 'I agree to receive marketing communications from Example Company.',
503 ),
504 ),
505 ),
506 ),
507 'context' =>
508 array(
509 'hutk' => $_POST['hubspotToken'],
510 'ipAddress' => $_POST['ipFormInput']
511 )
512 );
513
514 $dataForm = json_encode($data);
515 //echo "============json costruito da noi============";
516 //echo "<pre>";
517 //$json_pretty = json_encode(json_decode($dataForm), JSON_PRETTY_PRINT);
518 //echo $json_pretty;
519 //echo "</pre>";
520
521 SendData($dataForm, $url);
522}
523
524
525
526
527
528?>