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

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

127 lines 4.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\Conversational\Fields;
4
5 use BitCode\BitForm\Core\Util\FrontendHelpers;
6
7 class HtmlSelectField
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, $form_atomic_Cls_map, $formID, $value);
13 return $inputWrapper->wrapper($input);
14 }
15
16 private static function checkSelected($opt, $val)
17 {
18 $selected = '';
19 if (isset($opt->val) && $opt->val === $val) {
20 $selected = 'selected';
21 } elseif (isset($opt->lbl) && $opt->lbl === $val) {
22 $selected = 'selected';
23 } elseif (property_exists($opt, 'check')) {
24 $selected = 'selected';
25 }
26 return $selected;
27 }
28
29 private static function field($field, $rowID, $form_atomic_Cls_map, $formID, $val = null)
30 {
31 $fieldHelpers = new ConversationalFieldHelpers($formID, $field, $rowID, $form_atomic_Cls_map);
32 $disabled = $fieldHelpers->disabled();
33 $readonly = $fieldHelpers->readonly();
34 $name = $fieldHelpers->name();
35 $value = '';
36 if ($val) {
37 $value = $val;
38 } elseif (isset($field->val)) {
39 $value = $field->val;
40 }
41
42 $readonlyCls = $readonly ? 'readonly' : '';
43 $phHide = '';
44 $optionsHTML = '';
45 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
46 $contentCount = count($bfFrontendFormIds);
47 if ($fieldHelpers->property_exists_nested($field, 'phHide', true)) {
48 $phHide = <<<PHHIDE
49 <option
50 {$fieldHelpers->getCustomAttributes('slct-optn')}
51 class="{$fieldHelpers->getConversationalCls('slct-optn')} {$fieldHelpers->getCustomClasses('slct-optn')}"
52 value
53 >
54 {$fieldHelpers->kses_post($field->ph)}
55 </option>
56 PHHIDE;
57 }
58
59 if (property_exists($field, 'opt')) {
60 foreach ($field->opt as $opt) {
61 $disabled = property_exists($opt, 'disabled') ? 'disabled' : '';
62 if (property_exists($opt, 'type')) {
63 $optionsHTML .= <<<OPTGRP
64 <optgroup
65 {$fieldHelpers->getCustomAttributes('slct-opt-grp')}
66 class="{$fieldHelpers->getConversationalCls('slct-opt-grp')} {$fieldHelpers->getCustomClasses('slct-opt-grp')}"
67 label="{$fieldHelpers->esc_attr($opt->title)}"
68 {$disabled}
69 >
70 OPTGRP;
71 foreach ($opt->childs as $child) {
72 $val = isset($child->val) ? $child->val : $child->lbl;
73 $selected = self::checkSelected($child, $value);
74 $disabled = property_exists($child, 'disabled') ? 'disabled' : '';
75 $optionsHTML .= <<<OPT
76 <option
77 {$fieldHelpers->getCustomAttributes('slct-optn')}
78 class="{$fieldHelpers->getConversationalCls('slct-optn')} {$fieldHelpers->getCustomClasses('slct-optn')}"
79 value="{$fieldHelpers->esc_attr($val)}"
80 {$selected}
81 {$disabled}
82 >
83 {$fieldHelpers->kses_post($child->lbl)}
84 </option>
85 OPT;
86 }
87 $optionsHTML .= '</optgroup>';
88 } else {
89 $selected = self::checkSelected($opt, $value);
90 $val = isset($opt->val) ? $opt->val : $opt->lbl;
91 $optionsHTML .= <<<OPT
92 <option
93 {$fieldHelpers->getCustomAttributes('slct-optn')}
94 class="{$fieldHelpers->getConversationalCls('slct-optn')} {$fieldHelpers->getCustomClasses('slct-optn')}"
95 value="{$fieldHelpers->esc_attr($val)}"
96 {$selected}
97 {$disabled}
98 >
99 {$fieldHelpers->kses_post($opt->lbl)}
100 </option>
101 OPT;
102 }
103 }
104 }
105
106 return <<<HTMLSELECTFIELD
107 <div
108 {$fieldHelpers->getCustomAttributes('inp-fld-wrp')}
109 class="{$fieldHelpers->getConversationalCls('inp-fld-wrp')} {$fieldHelpers->getCustomClasses('inp-fld-wrp')}"
110 >
111 <select
112 {$fieldHelpers->getCustomAttributes('fld')}
113 id="{$rowID}-{$contentCount}"
114 class="{$fieldHelpers->getConversationalCls('fld')} {$fieldHelpers->getCustomClasses('fld')} {$readonlyCls}"
115 {$readonly}
116 {$disabled}
117 {$name}
118 value="{$fieldHelpers->esc_attr($value)}"
119 >
120 {$phHide}
121 {$optionsHTML}
122 </select>
123 </div>
124 HTMLSELECTFIELD;
125 }
126 }
127