PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.0
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 / CheckBoxField.php

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

156 lines 6.0 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 class CheckBoxField {
6 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value) {
7 $inputWrapper = new InputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
8 $input = self::field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
9 return $inputWrapper->wrapper($input);
10 }
11
12 private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value) {
13 $fieldHelpers = new FieldHelpers($field, $rowID, $form_atomic_Cls_map);
14
15 $req = $fieldHelpers->required();
16 $name = $fieldHelpers->name();
17 $checkBoxOptions = '';
18
19 if (property_exists($field, 'opt') && count($field->opt) > 0) {
20 $defaultValues = isset($field->val) ? explode(',', $field->val) : [];
21 foreach ($field->opt as $key => $opt) {
22 $value = isset($opt->val) ? $opt->val : $opt->lbl;
23 $check = '';
24 $req = '';
25 $disabled = '';
26 $href = htmlentities("#$rowID-ck-svg");
27 if ($fieldHelpers->property_exists_nested($opt, 'check', true)) {
28 $check = 'checked';
29 } else {
30 if (in_array($value, $defaultValues)) {
31 $check = 'checked';
32 }
33 }
34 if ($fieldHelpers->property_exists_nested($opt, 'req', true)) {
35 $req = 'required';
36 }
37 if ($fieldHelpers->property_exists_nested($field, 'valid->disabled', true)
38 || $fieldHelpers->property_exists_nested($opt, 'disabled', true)) {
39 $disabled = "disabled='disabled'";
40 }
41
42 $checkBoxOptions .= <<<CHECKBOXOPTIONS
43 <div
44 class="{$fieldHelpers->getAtomicCls('cw')} {$fieldHelpers->getCustomClasses('cw')}"
45 {$fieldHelpers->getCustomAttributes('cw')}
46 >
47 <input
48 id="{$rowID}-chk-{$key}"
49 type="checkbox"
50 class="{$fieldHelpers->getAtomicCls('ci')} {$fieldHelpers->getCustomClasses('ci')}"
51 {$disabled}
52 value="{$value}"
53 {$check}
54 {$req}
55 {$name}
56 />
57 <label
58 data-cl
59 for="{$rowID}-chk-{$key}"
60 class="{$fieldHelpers->getAtomicCls('cl')} {$fieldHelpers->getCustomClasses('cl')}"
61 {$fieldHelpers->getCustomAttributes('cl')}
62 >
63 <span
64 data-bx
65 class="{$fieldHelpers->getAtomicCls('bx')} {$fieldHelpers->getCustomClasses('bx')}"
66 {$fieldHelpers->getCustomAttributes('bx')}
67 >
68 <svg width="12" height="10" viewBox="0 0 12 10" class="{$fieldHelpers->getAtomicCls('svgwrp')} {$fieldHelpers->getCustomClasses('svgwrp')}">
69 <use data-ck-icn href="$href" class="{$fieldHelpers->getAtomicCls('ck-icn')} {$fieldHelpers->getCustomClasses('ck-icn')}" />
70 </svg>
71 </span>
72 <span
73 class="{$fieldHelpers->getAtomicCls('ct')} {$fieldHelpers->getCustomClasses('ct')}"
74 {$fieldHelpers->getCustomAttributes('ct')}
75 >
76 {$fieldHelpers->renderHTMR($opt->lbl)}
77 </span>
78 </label>
79 </div>
80 CHECKBOXOPTIONS;
81 }
82 }
83
84 //Other Option
85 $optCount = property_exists($field, 'opt') ? count($field->opt) : 0;
86 $inputPh = isset($field->otherInpPh) ? "placeholder='$field->otherInpPh'" : "placeholder='Other...'";
87 $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : '';
88 if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) {
89 $checkBoxOptions .= <<<CHECKBOXOPTIONS
90 <div
91 class="{$fieldHelpers->getAtomicCls('cw')} {$fieldHelpers->getCustomClasses('cw')}"
92 {$fieldHelpers->getCustomAttributes('cw')}
93 >
94 <input
95 id="{$rowID}-chk-{$optCount}"
96 data-oopt="{$rowID}"
97 type="checkbox"
98 class="{$fieldHelpers->getAtomicCls('ci')} {$fieldHelpers->getCustomClasses('ci')}"
99 {$disabled}
100 value=""
101 {$name}
102 />
103 <label
104 data-cl
105 for="{$rowID}-chk-{$optCount}"
106 class="{$fieldHelpers->getAtomicCls('cl')} {$fieldHelpers->getCustomClasses('cl')}"
107 {$fieldHelpers->getCustomAttributes('cl')}
108 >
109 <span
110 data-bx
111 class="{$fieldHelpers->getAtomicCls('bx')} {$fieldHelpers->getAtomicCls('ck')} {$fieldHelpers->getCustomClasses('ck')}"
112 {$fieldHelpers->getCustomAttributes('ck')}
113 >
114 <svg width="12" height="10" viewBox="0 0 12 10" class="{$fieldHelpers->getAtomicCls('svgwrp')} {$fieldHelpers->getCustomClasses('svgwrp')}">
115 <use data-ck-icn href="#$rowID-ck-svg" class="{$fieldHelpers->getAtomicCls('ck-icn')} {$fieldHelpers->getCustomClasses('ck-icn')}" />
116 </svg>
117 </span>
118 <span
119 class="{$fieldHelpers->getAtomicCls('ct')} {$fieldHelpers->getCustomClasses('ct')}"
120 {$fieldHelpers->getCustomAttributes('ct')}
121 >
122 Other..
123 </span>
124 </label>
125 <div data-oinp-wrp class="{$fieldHelpers->getAtomicCls('other-inp-wrp')}">
126 <input
127 data-bf-other-inp='{$rowID}-chk-{$optCount}'
128 type="text"
129 class="{$fieldHelpers->getAtomicCls('other-inp')} {$fieldHelpers->getCustomClasses('other-inp')}"
130 {$inpReq}
131 {$inputPh}
132 />
133 </div>
134 </div>
135 CHECKBOXOPTIONS;
136 }
137
138 return <<<CHECKBOXFIELD
139 <div
140 class="{$fieldHelpers->getAtomicCls('cc')} {$fieldHelpers->getCustomClasses('cc')}"
141 {$fieldHelpers->getCustomAttributes('cc')}
142 >
143 <svg class="{$fieldHelpers->getAtomicCls('cks')}">
144 <symbol id="{$rowID}-ck-svg" viewBox="0 0 12 10">
145 <polyline
146 class="{$fieldHelpers->getAtomicCls('ck-svgline')}"
147 points="1.5 6 4.5 9 10.5 1"
148 ></polygon>
149 </symbol>
150 </svg>
151 {$checkBoxOptions}
152 </div>
153 CHECKBOXFIELD;
154 }
155 }
156