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

78 lines 3.4 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 $fldKey = $childFldKey->fldKey;
31 $childField = $fields->$fldKey;
32
33 $input = TextField::init($childField, $fldKey, $field_name . '_confirm', $form_atomic_Cls_map, $formID, $error, $value);
34 $parentChildHTML .= $inputWrapper->childFieldWrapper($input, '', null, $fldKey);
35 }
36 } elseif ('name' === $field->typ) {
37 $parentFieldValue = '';
38 if (isset($field->val)) {
39 $value = $field->val;
40 if (is_array($value)) {
41 $parentFieldValue = (object) $value;
42 } elseif (is_string($value) && !empty($value)) {
43 $parentFieldValue = json_decode($value);
44 }
45 }
46 // for name field there will be no primary field just child fields
47 foreach ($childFields as $childFldKey) {
48 if (!isset($childFldKey->fldKey) || !isset($fields->{$childFldKey->fldKey})) {
49 continue;
50 }
51 $fldKey = $childFldKey->fldKey;
52 $childField = $fields->{$fldKey};
53 $isDeactive = property_exists($childField, 'isDeactive') && $childField->isDeactive;
54 if ($isDeactive) {
55 continue;
56 }
57 $childFieldName = '';
58 if (preg_match('/\[([^\]]+)\]/', $childField->fieldName, $matches)) {
59 $childFieldName = $matches[1];
60 }
61 if ($childFieldName && is_object($parentFieldValue) && property_exists($parentFieldValue, $childFieldName)) {
62 $childField->val = $parentFieldValue->{$childFieldName};
63 }
64 $input = TextField::init($childField, $fldKey, $field_name . '_confirm', $form_atomic_Cls_map, $formID, $error, $value);
65 $parentChildHTML .= $inputWrapper->childFieldWrapper($input, '', null, $fldKey);
66 }
67 }
68
69 return self::shouldRenderChild($field) ? $inputWrapper->parentFieldWrapper($parentChildHTML) : TextField::init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
70 }
71
72 private static function shouldRenderChild($field)
73 {
74 return (in_array($field->typ, ['email', 'password']) && property_exists($field, 'confirm') && true === $field->confirm)
75 || ('name' === $field->typ && property_exists($field, 'childFields') && !empty((array) $field->childFields));
76 }
77 }
78