PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.9.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.9.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 2.10.2 All 137 releases
bit-form / includes / Frontend / Form / View / Theme / Fields / RadioBoxField.php

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