/
CFDBIntegrationCFormsII.php
103 lines (82 loc) · 3.04 KB
/
CFDBIntegrationCFormsII.php
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
"Contact Form to Database" Copyright (C) 2011-2016 Michael Simpson (email : michael.d.simpson@gmail.com)
This file is part of Contact Form to Database.
Contact Form to Database is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Contact Form to Database is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Contact Form to Database.
If not, see <http://www.gnu.org/licenses/>.
*/
class CFDBIntegrationCFormsII {
/**
* @var CF7DBPlugin
*/
var $plugin;
/**
* @param $plugin CF7DBPlugin
*/
function __construct($plugin) {
$this->plugin = $plugin;
}
public function registerHooks() {
add_action('cforms2_after_processing_action', array(&$this, 'saveFormData'), 10, 1);
}
public function saveFormData($trackf) {
/*
[id] =>
[data] => Array
(
[$$$1] => Fieldset
[Fieldset] => My Fieldset
[$$$2] => Your Name
[Your Name] => Mike
[$$$3] => Email
[Email] => me@example.com
[$$$4] => Website
[Website] => http://example.com
[$$$5] => Message
[Message] => example
)
[title] => Your default form
[uploaded_files] => Array
(
)
*/
//$this->plugin->getErrorLog()->log(print_r($trackf, true) . "\n\n"); // debug
$form_data = array();
$uploaded_files = array();
$upload_in = array();
if (is_array($trackf['uploaded_files'])) {
$upload_in = $trackf['uploaded_files'];
}
foreach ($trackf['data'] as $key => $value) {
if (strpos($key, '$$$') === false) {
// filter multi-step forms' prefix
$key = preg_replace('/^cf_form[0-9]*_/', '', $key, 1);
$upl_marker_pos = strpos($key, '[*');
if ($upl_marker_pos === false) {
$form_data[$key] = $value;
} else foreach ($upload_in as $file) {
if (substr($file['name'], -strlen($value)) === $value) {
$key = substr($key, 0, $upl_marker_pos);
$uploaded_files[$key] = $file['name'];
break;
}
}
}
}
$form_data['submit_time'] = $trackf['submit_time'];
$cfdb_data = (object)array(
'title' => $trackf['title'],
'posted_data' => $form_data,
'uploaded_files' => $uploaded_files);
do_action_ref_array('cfdb_submit', array(&$cfdb_data));
}
}