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

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

124 lines 4.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\Conversational\Fields;
4
5 use BitCode\BitForm\Core\Util\FrontendHelpers;
6
7 class RatingField
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 field($field, $rowID, $form_atomic_Cls_map, $formID, $value)
17 {
18 $fieldHelpers = new ConversationalFieldHelpers($formID, $field, $rowID, $form_atomic_Cls_map);
19
20 $name = $fieldHelpers->name();
21 $req = $fieldHelpers->required();
22
23 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
24 $contentCount = count($bfFrontendFormIds);
25
26 $ratingOption = '';
27
28 $checkedIndex = '';
29
30 if (isset($field->opt)) {
31 $defaultValue = isset($field->val) ? $field->val : '';
32 foreach ($field->opt as $key => $opt) {
33 if ($defaultValue && $defaultValue === $opt->val) {
34 $checkedIndex = $key;
35 } elseif (isset($opt->check) && true === $opt->check) {
36 $checkedIndex = $key;
37 }
38 }
39
40 $checkedCls = null;
41
42 foreach ($field->opt as $key => $opt) {
43 $val = $opt->val;
44 $img = $opt->img;
45 $lbl = $opt->lbl;
46 $checked = '';
47
48 // if ($defaultValue && $opt->val === $defaultValue) {
49 // $checked = "checked='checked'";
50 // } elseif (isset($opt->check) && true === $opt->check) {
51 // $checked = "checked='{$opt->check}'";
52 // } else {
53 // $checked = '';
54 // }
55
56 if ($defaultValue) {
57 if ($opt->val === $defaultValue) {
58 $checked = "checked='1'";
59 }
60 } else {
61 if (isset($opt->check) && true === $opt->check) {
62 $checked = "checked='{$opt->check}'";
63 } else {
64 $checked = '';
65 }
66 }
67
68 if (!empty($checkedIndex) && $key <= $checkedIndex) {
69 $checkedCls = $rowID . '-rating-selected';
70 } else {
71 $checkedCls = null;
72 }
73 $ratingOption .= <<<RATINGOPTION
74 <label
75 class="{$fieldHelpers->getConversationalMultiCls('rating-lbl')} {$fieldHelpers->getCustomClasses('rating-lbl')}"
76 for="{$rowID}-{$contentCount}-rating-{$key}"
77 {$fieldHelpers->getCustomAttributes('rating-lbl')}
78 data-indx="{$key}"
79 >
80 <input
81 type="radio"
82 class="{$fieldHelpers->getConversationalMultiCls('rating-input')} {$fieldHelpers->getCustomClasses('rating-input')}"
83 {$name}
84 value={$val}
85 aria-label="{$lbl}"
86 id="{$rowID}-{$contentCount}-rating-{$key}"
87 {$checked}
88 {$req}
89 {$fieldHelpers->getCustomAttributes('rating-input')}
90 />
91 <img
92 class="{$fieldHelpers->getConversationalMultiCls('rating-img')} {$fieldHelpers->getCustomClasses('rating-img')} {$checkedCls}"
93 src="{$img}"
94 alt="{$lbl}"
95 aria-label="{$lbl}"
96 {$fieldHelpers->getCustomAttributes('rating-img')}
97 />
98 </label>
99 RATINGOPTION;
100 }
101 }
102
103 return <<<RATINGFIELD
104 <div
105 {$fieldHelpers->getCustomAttributes('inp-fld-wrp')}
106 class="{$fieldHelpers->getConversationalMultiCls('inp-fld-wrp')} {$fieldHelpers->getCustomClasses('inp-fld-wrp')}"
107 >
108 <div
109 {$fieldHelpers->getCustomAttributes('rating-wrp')}
110 class="{$fieldHelpers->getConversationalMultiCls('rating-wrp')} {$fieldHelpers->getCustomClasses('rating-wrp')}"
111 tabindex="0"
112 >
113 {$ratingOption}
114 </div>
115 <span
116 class="{$fieldHelpers->getConversationalMultiCls('rating-msg')} {$fieldHelpers->getCustomClasses('rating-msg')}"
117 {$fieldHelpers->getCustomAttributes('rating-msg')}
118 >
119 </span>
120 </div>
121 RATINGFIELD;
122 }
123 }
124