PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.15.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.15.3
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
← All changes | includes/Core/Util/FieldValueHandler.php +45 -32 2.10.02.15.3 View file →
@@ -1,8 +1,10 @@
1 1 <?php
2 2
3 3 namespace BitCode\BitForm\Core\Util;
4 4
5 +use BitCode\BitForm\Admin\Form\Helpers;
6 +
5 7 final class FieldValueHandler
6 8 {
7 9 public static function replaceFieldWithValue($stringToReplaceField, $fieldValues)
8 10 {
@@ -35,9 +37,9 @@
35 37 } else {
36 38 $fieldValue = $singleTargetVal;
37 39 }
38 40 }
39 - // $fieldValue = wp_json_encode($targetFieldValue);
41 + // $fieldValue = wp_json_encode($targetFieldValue);
40 42 } else {
41 43 $fieldValue = strval($targetFieldValue);
42 44 }
43 45 $stringToReplaceField = str_replace($value, $fieldValue, $stringToReplaceField);
@@ -46,20 +48,21 @@
46 48 }
47 49 }
48 50
49 51 // check if the string is a function like : "${_bf_calc(${b27-5}*10)}"
50 - if (self::isFunction($stringToReplaceField)) {
51 - $functionName = self::getFunctionName($stringToReplaceField);
52 + // TO DO: Implement the function properly
53 + // if (self::isFunction($stringToReplaceField)) {
54 + // $functionName = self::getFunctionName($stringToReplaceField);
52 55
53 - switch ($functionName) {
54 - case '_bf_calc':
55 - return self::getFunctionParameter($stringToReplaceField);
56 - case '_bf_count':
57 - return self::getCountValue($stringToReplaceField);
58 - default:
59 - return 0;
60 - }
61 - }
56 + // switch ($functionName) {
57 + // case '_bf_calc':
58 + // return self::getFunctionParameter($stringToReplaceField);
59 + // case '_bf_count':
60 + // return self::getCountValue($stringToReplaceField);
61 + // default:
62 + // return 0;
63 + // }
64 + // }
62 65 return $stringToReplaceField;
63 66 }
64 67
65 68 /**
@@ -170,10 +173,11 @@
170 173
171 174 public static function formatFieldValueForMail($fields, $fieldValues)
172 175 {
173 176 $formattedFldValues = $fieldValues;
174 - $file_upload_types = ['file-up', 'advanced-file-up'];
175 -
177 + $repeaterFieldKey = [];
178 + $file_upload_types = Helpers::$file_upload_types;
179 + $repeated_array_type_data_fields = Helpers::$repeated_array_type_data_fields;
176 180 foreach ($fields as $fldKey => $fldData) {
177 181 if (in_array($fldData->typ, $file_upload_types)) {
178 182 continue;
179 183 }
@@ -183,32 +187,39 @@
183 187 // $formattedFldValues[$fldKey] = htmlspecialchars(implode(', ', $value));
184 188 // } else {
185 189 // $formattedFldValues[$fldKey] = htmlspecialchars($value);
186 190 // }
191 +
187 192 if (is_array($value)) {
188 - foreach ($value as $subValue) {
189 - if (is_array($subValue)) {
190 - foreach ($subValue as $subSubKey => $subSubValue) {
191 - $stringValue = is_array($subSubValue) ? implode(', ', $subSubValue) : $subSubValue . ', ';
192 - $stringValue = htmlspecialchars($stringValue);
193 - if (array_key_exists($subSubKey, $formattedFldValues)) {
194 - $formattedFldValues[$subSubKey] .= $stringValue;
193 + $arrValue = '';
194 + foreach ($value as $v) {
195 + if (is_array($v)) {
196 + foreach ($v as $k1 => $v1) {
197 + if (array_key_exists($k1, $repeaterFieldKey)) {
198 + $oldValue = $repeaterFieldKey[$k1];
199 + if (is_array($v1) && in_array($fields->{$k1}->typ, $repeated_array_type_data_fields)) {
200 + $newValues = '[' . implode(', ', $v1) . '] ';
201 + if (!preg_match('/\[.*\]/', $oldValue)) {
202 + $oldValue = '[' . $oldValue . '] ';
203 + }
204 + } else {
205 + $newValues = $v1;
206 + }
207 + $repeaterFieldKey[$k1] = $oldValue . ', ' . $newValues;
195 208 } else {
196 - $formattedFldValues[$subSubKey] = $stringValue;
209 + if (!empty($v1) && is_array($v1)) {
210 + $repeaterFieldKey[$k1] = htmlspecialchars(implode(', ', $v1));
211 + } else {
212 + $repeaterFieldKey[$k1] = htmlspecialchars($v1);
213 + }
197 214 }
198 215 }
199 216 } else {
200 - if (array_key_exists($fldKey, $formattedFldValues)) {
201 - if (is_array($formattedFldValues[$fldKey])) {
202 - $formattedFldValues[$fldKey] = htmlspecialchars(implode(', ', $formattedFldValues[$fldKey]) . ', ');
203 - } else {
204 - $formattedFldValues[$fldKey] .= htmlspecialchars($subValue);
205 - }
206 - } else {
207 - $formattedFldValues[$fldKey] = htmlspecialchars($subValue . ', ');
208 - }
217 + $arrValue .= $v . ', ';
209 218 }
210 219 }
220 + $formattedFldValues[$fldKey] = htmlspecialchars(rtrim($arrValue, ', '));
221 + $arrValue = '';
211 222 } else {
212 223 $formattedFldValues[$fldKey] = htmlspecialchars($value);
213 224 }
214 225 if ('textarea' === $fldData->typ) {
@@ -219,7 +230,9 @@
219 230 }
220 231 }
221 232 }
222 233
223 - return $formattedFldValues;
234 + $merge_values = array_merge($fieldValues, $formattedFldValues);
235 + $merge_values = array_merge($merge_values, $repeaterFieldKey);
236 + return $merge_values;
224 237 }
225 238 }