PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.3
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 2.10.2 All 137 releases
bit-form / includes / Core / Util / FieldValueHandler.php

FieldValueHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.3, at includes/Core/Util/FieldValueHandler.php

53 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace BitCode\BitForm\Core\Util;
3
4 final class FieldValueHandler
5 {
6 public static function replaceFieldWithValue($stringToReplaceField, $fieldValues)
7 {
8 if (empty($stringToReplaceField)) {
9 return $stringToReplaceField;
10 }
11 if (!is_string($stringToReplaceField)) {
12 $stringToReplaceField = wp_json_encode($stringToReplaceField);
13 }
14 $fieldPattern = '/\${\w[^ ${}]*}/';
15 preg_match_all($fieldPattern, $stringToReplaceField, $matchedField);
16 if (empty($matchedField)) {
17 return $stringToReplaceField;
18 }
19 $uniqueFieldsInStr = array_unique($matchedField[0]);
20 foreach ($uniqueFieldsInStr as $key => $value) {
21 $fieldName = substr($value, 2, strlen($value)-3);
22 if (isset($fieldValues[$fieldName])) {
23 $targetFieldValue = isset($fieldValues[$fieldName]['value']) ? $fieldValues[$fieldName]['value'] : $fieldValues[$fieldName];
24 if (gettype($targetFieldValue) === 'array' || gettype($targetFieldValue) === 'object') {
25 $fieldValue = wp_json_encode($targetFieldValue);
26 } else {
27 $fieldValue = strval($targetFieldValue);
28 }
29 $stringToReplaceField = str_replace($value, $fieldValue, $stringToReplaceField);
30 } elseif (array_search($fieldName, $fieldValues) !== false) {
31 $stringToReplaceField = str_replace($value, '', $stringToReplaceField);
32 }
33 }
34 return $stringToReplaceField;
35 }
36
37 public static function validateMailArry($emailAddresses, $fieldValues)
38 {
39 if (!is_array($emailAddresses)) {
40 return [FieldValueHandler::replaceFieldWithValue($emailAddresses, $fieldValues)];
41 }
42 foreach ($emailAddresses as $key=>$email) {
43 if (!is_email($email)) {
44 $email = FieldValueHandler::replaceFieldWithValue($email, $fieldValues);
45 if (is_email($email)) {
46 $emailAddresses[$key] = $email;
47 }
48 }
49 }
50 return $emailAddresses;
51 }
52 }
53