PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.10.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.10.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 / Conversational / Fields / RadioBoxField.php

RadioBoxField.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.10.1, at includes/Frontend/Form/View/Conversational/Fields/RadioBoxField.php

155 lines 5.9 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\Conversational\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 ConversationalInputWrapper($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 ConversationalFieldHelpers($formID, $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 $keyChar = chr(65 + $key);
34 if ($fieldHelpers->property_exists_nested($opt, 'check', true)) {
35 $check = "checked='{$opt->check}'";
36 } else {
37 if ($value === $defaultValue) {
38 $check = "checked='checked'";
39 }
40 }
41 if ($fieldHelpers->property_exists_nested($opt, 'req', true)) {
42 $req = "required='{$opt->req}'";
43 }
44 if ($fieldHelpers->property_exists_nested($field, 'valid->disabled', true)
45 || $fieldHelpers->property_exists_nested($opt, 'disabled', true)) {
46 $disabled = "disabled='disabled'";
47 }
48
49 $radioBoxOptions .= <<<RADIOBOXOPTIONS
50 <div
51 {$fieldHelpers->getCustomAttributes('cw')}
52 class="{$fieldHelpers->getConversationalCls('cw')} {$fieldHelpers->getCustomClasses('cw')}"
53 >
54 <input
55 {$fieldHelpers->getCustomAttributes('ci')}
56 id="{$rowID}-{$contentCount}-chk-{$key}"
57 type="radio"
58 class="{$fieldHelpers->getConversationalCls('ci')} {$fieldHelpers->getCustomClasses('ci')}"
59 value="{$fieldHelpers->esc_attr($value)}"
60 {$check}
61 {$name}
62 {$req}
63 {$disabled}
64 />
65 <label
66 {$fieldHelpers->getCustomAttributes('cl')}
67 data-cl
68 for="{$rowID}-{$contentCount}-chk-{$key}"
69 class="{$fieldHelpers->getConversationalCls('cl')} {$fieldHelpers->getCustomClasses('cl')}"
70 >
71 <span
72 {$fieldHelpers->getCustomAttributes('bx')}
73 data-bx
74 class="{$fieldHelpers->getConversationalCls('bx')} {$fieldHelpers->getCustomClasses('bx')}"
75 >
76 <span class="{$fieldHelpers->getConversationalCls('opt-key-lbl')}">Key</span>
77 <span class="{$fieldHelpers->getConversationalCls('opt-key')}">{$keyChar}</span>
78 </span>
79 <span
80 {$fieldHelpers->getCustomAttributes('ct')}
81 class="{$fieldHelpers->getConversationalCls('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 $keyChar = chr(65 + count($field->opt));
97 $radioBoxOptions .= <<<RADIOBOXOPTIONS
98 <div
99 {$fieldHelpers->getCustomAttributes('cw')}
100 class="{$fieldHelpers->getConversationalCls('cw')} {$fieldHelpers->getCustomClasses('cw')}"
101 >
102 <input
103 {$fieldHelpers->getCustomAttributes('ci')}
104 id="{$rowID}-{$contentCount}-chk-{$optCount}"
105 data-oopt="{$rowID}"
106 type="radio"
107 class="{$fieldHelpers->getConversationalCls('ci')} {$fieldHelpers->getCustomClasses('ci')}"
108 value=""
109 {$check}
110 {$name}
111 />
112 <label
113 {$fieldHelpers->getCustomAttributes('cl')}
114 data-cl
115 for="{$rowID}-{$contentCount}-chk-{$optCount}"
116 class="{$fieldHelpers->getConversationalCls('cl')} {$fieldHelpers->getCustomClasses('cl')}"
117 >
118 <span
119 {$fieldHelpers->getCustomAttributes('rdo')}
120 data-bx
121 class="{$fieldHelpers->getConversationalCls('bx')} {$fieldHelpers->getConversationalCls('rdo')} {$fieldHelpers->getCustomClasses('rdo')}"
122 >
123 <span class="{$fieldHelpers->getConversationalCls('opt-key')}">{$keyChar}</span>
124 </span>
125 <span
126 {$fieldHelpers->getCustomAttributes('ct')}
127 class="{$fieldHelpers->getConversationalCls('ct')} {$fieldHelpers->getCustomClasses('ct')}"
128 >
129 Other..
130 </span>
131 </label>
132 <div data-oinp-wrp class="{$fieldHelpers->getConversationalCls('other-inp-wrp')}">
133 <input
134 data-bf-other-inp="{$rowID}-chk-{$optCount}"
135 type="text"
136 class="{$fieldHelpers->getConversationalCls('other-inp')}"
137 {$inpReq}
138 placeholder="{$fieldHelpers->esc_attr($inputPh)}"
139 >
140 </div>
141 </div>
142 RADIOBOXOPTIONS;
143 }
144
145 return <<<RADIOBOX
146 <div
147 {$fieldHelpers->getCustomAttributes('cc')}
148 class="{$fieldHelpers->getConversationalCls('cc')} {$fieldHelpers->getCustomClasses('cc')}"
149 >
150 {$radioBoxOptions}
151 </div>
152 RADIOBOX;
153 }
154 }
155