PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
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
bit-form / includes / Frontend / Form / View / Theme / Fields / FieldWithChild.php

FieldWithChild.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.3.1, at includes/Frontend/Form/View/Theme/Fields/FieldWithChild.php

81 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields;
4
5 use BitCode\BitForm\Core\Form\FormManager;
6
7 class FieldWithChild
8 {
9 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
10 {
11 $inputWrapper = new ClassicInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
12 $input = self::field($inputWrapper, $field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
13
14 return $input;
15 }
16
17 private static function field($inputWrapper, $field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
18 {
19 //to be implemented by child classes
20 $formManager = FormManager::getInstance($formID);
21 $fields = $formManager->getFormContent()->fields;
22 $parentChildHTML = '';
23 $childFields = isset($field->childFields) ? $field->childFields : [];
24
25 if (in_array($field->typ, ['email', 'password'])) {
26 // if it's email or password field primar field will be inside parent wrapper
27 $parentInputHtml = TextField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
28 $parentChildHTML .= $inputWrapper->childFieldWrapper($parentInputHtml);
29 foreach ($childFields as $childFldKey) {
30 if (!isset($childFldKey->fldKey) || !isset($fields->{$childFldKey->fldKey}) || !is_object($fields->{$childFldKey->fldKey})) {
31 continue;
32 }
33 $fldKey = $childFldKey->fldKey;
34 $childField = $fields->$fldKey;
35
36 $input = TextField::init($childField, $fldKey, $field_name . '_confirm', $form_atomic_Cls_map, $formID, $error, $value);
37 $parentChildHTML .= $inputWrapper->childFieldWrapper($input, '', null, $fldKey);
38 }
39 } elseif ('name' === $field->typ) {
40 $parentFieldValue = '';
41 if (isset($field->val)) {
42 $value = $field->val;
43 if (is_array($value)) {
44 $parentFieldValue = (object) $value;
45 } elseif (is_string($value) && !empty($value)) {
46 $parentFieldValue = json_decode($value);
47 }
48 }
49 // for name field there will be no primary field just child fields
50 foreach ($childFields as $childFldKey) {
51 if (!isset($childFldKey->fldKey) || !isset($fields->{$childFldKey->fldKey}) || !is_object($fields->{$childFldKey->fldKey})) {
52 continue;
53 }
54 $fldKey = $childFldKey->fldKey;
55 $childField = $fields->{$fldKey};
56 $isDeactive = property_exists($childField, 'isDeactive') && $childField->isDeactive;
57 if ($isDeactive) {
58 continue;
59 }
60 $childFieldName = '';
61 if (preg_match('/\[([^\]]+)\]/', $childField->fieldName, $matches)) {
62 $childFieldName = $matches[1];
63 }
64 if ($childFieldName && is_object($parentFieldValue) && property_exists($parentFieldValue, $childFieldName)) {
65 $childField->val = $parentFieldValue->{$childFieldName};
66 }
67 $input = TextField::init($childField, $fldKey, $field_name . '_confirm', $form_atomic_Cls_map, $formID, $error, $value);
68 $parentChildHTML .= $inputWrapper->childFieldWrapper($input, '', null, $fldKey);
69 }
70 }
71
72 return self::shouldRenderChild($field) ? $inputWrapper->parentFieldWrapper($parentChildHTML) : TextField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
73 }
74
75 private static function shouldRenderChild($field)
76 {
77 return (in_array($field->typ, ['email', 'password']) && property_exists($field, 'confirm') && true === $field->confirm)
78 || ('name' === $field->typ && property_exists($field, 'childFields') && !empty((array) $field->childFields));
79 }
80 }
81