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 / Conversational / Fields / RadioBoxField.php

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

168 lines 6.7 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 $ariaDescribedBy = $fieldHelpers->ariaDescribedBy();
22 $ariaRequired = $fieldHelpers->ariaRequired();
23 $labelId = $fieldHelpers->getLabelId();
24 $value = '';
25 $radioBoxOptions = '';
26 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
27 $contentCount = count($bfFrontendFormIds);
28 if (property_exists($field, 'opt') && count($field->opt) > 0) {
29 $defaultValue = isset($field->val) ? $field->val : '';
30 foreach ($field->opt as $key => $opt) {
31 $value = isset($opt->val) ? $opt->val : $opt->lbl;
32 $check = '';
33 $req = '';
34 $lbl = $fieldHelpers->renderHTMR($opt->lbl);
35 $disabled = '';
36 $keyChar = chr(65 + $key);
37 if ($fieldHelpers->property_exists_nested($opt, 'check', true)) {
38 $check = "checked='{$opt->check}'";
39 } else {
40 if ($value === $defaultValue) {
41 $check = "checked='checked'";
42 }
43 }
44 if ($fieldHelpers->property_exists_nested($opt, 'req', true)) {
45 $req = "required='{$opt->req}'";
46 }
47 if ($fieldHelpers->property_exists_nested($field, 'valid->disabled', true)
48 || $fieldHelpers->property_exists_nested($opt, 'disabled', true)) {
49 $disabled = "disabled='disabled'";
50 }
51
52 $radioBoxOptions .= '<div
53 ' . $fieldHelpers->getCustomAttributes('cw') . '
54 class="' . $fieldHelpers->getConversationalCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '"
55 >
56 <input
57 ' . $fieldHelpers->getCustomAttributes('ci') . '
58 id="' . $rowID . '-' . $contentCount . '-chk-' . $key . '"
59 type="radio"
60 role="radio"
61 class="' . $fieldHelpers->getConversationalCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '"
62 value="' . $fieldHelpers->esc_attr($value) . '"
63 ' . $check . '
64 ' . $name . '
65 ' . $req . '
66 ' . $disabled . '
67 />
68 <label
69 ' . $fieldHelpers->getCustomAttributes('cl') . '
70 data-cl
71 for="' . $rowID . '-' . $contentCount . '-chk-' . $key . '"
72 class="' . $fieldHelpers->getConversationalCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '"
73 >
74 <span
75 ' . $fieldHelpers->getCustomAttributes('bx') . '
76 data-bx
77 class="' . $fieldHelpers->getConversationalCls('bx') . ' ' . $fieldHelpers->getCustomClasses('bx') . '"
78 >
79 <span class="' . $fieldHelpers->getConversationalCls('opt-key-lbl') . '">Key</span>
80 <span class="' . $fieldHelpers->getConversationalCls('opt-key') . '">' . $keyChar . '</span>
81 </span>
82 <span
83 ' . $fieldHelpers->getCustomAttributes('ct') . '
84 class="' . $fieldHelpers->getConversationalCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '"
85 >
86 ' . $fieldHelpers->kses_post($lbl) . '
87 </span>
88 </label>
89 </div>
90 ';
91 }
92 }
93
94 //Other Option
95 $optCount = property_exists($field, 'opt') ? count($field->opt) : 0;
96 $otherOptLbl = !empty($field->otherOptLbl) ? $field->otherOptLbl : __('Other...', 'bit-form');
97 $inputPh = isset($field->otherInpPh) ? $field->otherInpPh : 'Other...';
98 $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : '';
99 if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) {
100 $keyChar = chr(65 + count($field->opt));
101 $radioBoxOptions .= '
102 <div
103 ' . $fieldHelpers->getCustomAttributes('cw') . '
104 class="' . $fieldHelpers->getConversationalCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '"
105 >
106 <input
107 ' . $fieldHelpers->getCustomAttributes('ci') . '
108 id="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '"
109 data-oopt="' . $rowID . '"
110 type="radio"
111 class="' . $fieldHelpers->getConversationalCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '"
112 value=""
113 role="radio"
114 ' . $name . '
115 />
116 <label
117 ' . $fieldHelpers->getCustomAttributes('cl') . '
118 data-cl
119 for="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '"
120 class="' . $fieldHelpers->getConversationalCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '"
121 >
122 <span
123 ' . $fieldHelpers->getCustomAttributes('rdo') . '
124 data-bx
125 class="' . $fieldHelpers->getConversationalCls('bx') . ' ' . $fieldHelpers->getConversationalCls('rdo') . ' ' . $fieldHelpers->getCustomClasses('rdo') . '"
126 >
127 <span class="' . $fieldHelpers->getConversationalCls('opt-key') . '">' . $keyChar . '</span>
128 </span>
129 <span
130 ' . $fieldHelpers->getCustomAttributes('ct') . '
131 class="' . $fieldHelpers->getConversationalCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '"
132 >
133 ' . $otherOptLbl . '
134 </span>
135 </label>
136 <div data-oinp-wrp class="' . $fieldHelpers->getConversationalCls('other-inp-wrp') . '">
137 <input
138 data-bf-other-inp="' . $rowID . '-chk-' . $optCount . '"
139 type="text"
140 class="' . $fieldHelpers->getConversationalCls('other-inp') . '"
141 ' . $inpReq . '
142 placeholder="' . $fieldHelpers->esc_attr($inputPh) . '"
143 />
144 </div>
145 </div>
146 ';
147 }
148
149 return sprintf(
150 '
151 <div
152 %1$s
153 class="%2$s"
154 role="radiogroup"
155 aria-labelledby="%3$s"
156 %4$s
157 >
158 %5$s
159 </div>',
160 $fieldHelpers->getCustomAttributes('cc'),
161 $fieldHelpers->getConversationalCls('cc') . ' ' . $fieldHelpers->getCustomClasses('cc'),
162 $labelId,
163 $ariaDescribedBy,
164 $radioBoxOptions
165 );
166 }
167 }
168