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

FormViewHelper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.4, at includes/Frontend/Form/View/FormViewHelper.php

205 lines 7.6 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;
4
5 use BitCode\BitForm\Frontend\Form\FrontendFormManager;
6
7 class FormViewHelper
8 {
9 private $_formContents;
10 private $_formInfo;
11 private $_layout;
12 private $_form;
13 private $_fieldHelpers;
14
15 public function __construct(FrontendFormManager $form, $form_contents)
16 {
17 $this->_form = $form;
18 $this->_formContents = $form_contents;
19 $this->_formInfo = isset($form_contents->formInfo) ? $form_contents->formInfo : '';
20 $this->_layout = isset($form_contents->layout) ? $form_contents->layout : '';
21 }
22
23 private function getFormInfoProperty($propertyName)
24 {
25 return isset($this->_formInfo->{$propertyName}) ? $this->_formInfo->{$propertyName} : null;
26 }
27
28 private function getFormId()
29 {
30 return $this->_form->getFormID();
31 }
32
33 public function filterHtml($str)
34 {
35 return wp_kses_post(str_replace('$_bf_$', '\\', $str));
36 }
37
38 private function getIconMarkup($source, $classElement)
39 {
40 if (empty($source)) {
41 return '';
42 }
43 return <<<ICON
44 <img
45 class="{$this->_form->getAtomicCls($classElement)} _frm-b-stp-icn"
46 src="{$source}"
47 alt=""
48 />
49 ICON;
50 }
51
52 private function getHeaderLabelMarkup($lbl, $preIcn, $sufIcn, $uniqClass)
53 {
54 $formID = $this->getFormId();
55 return <<<HEADERLABEL
56 <span class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-hdr-{$uniqClass}")} _frm-b-stp-hdr-{$uniqClass}'>
57 {$this->getIconMarkup($preIcn, "_frm-b{$formID}-stp-{$uniqClass}-pre-i")}
58 {$this->filterHtml($lbl)}
59 {$this->getIconMarkup($sufIcn, "_frm-b{$formID}-stp-{$uniqClass}-suf-i")}
60 </span>
61 HEADERLABEL;
62 }
63
64 private function getStepButton($btnSettings)
65 {
66 $key = $btnSettings->key;
67 $txt = $btnSettings->txt;
68 $btnTyp = $btnSettings->typ;
69 $formID = $this->getFormId();
70 $preIcn = isset($btnSettings->preIcn) ? $btnSettings->preIcn : null;
71 $sufIcn = isset($btnSettings->sufIcn) ? $btnSettings->sufIcn : null;
72 $preIcnMrkp = $this->getIconMarkup($preIcn, "_frm-b{$formID}-{$key}-pre-i");
73 $sufIcnMrkp = $this->getIconMarkup($sufIcn, "_frm-b{$formID}-{$key}-suf-i");
74 $btnSpinner = '<span class="bf-spinner d-none"></span>';
75 return <<<BUTTON
76 <button
77 class="{$this->_form->getAtomicCls("_frm-b{$formID}-{$key}")} {$key}"
78 name="{$key}"
79 type="{$btnTyp}"
80 >
81 {$preIcnMrkp}
82 {$this->filterHtml($txt)}
83 {$sufIcnMrkp}
84 {$btnSpinner}
85 </button>
86 BUTTON;
87 }
88
89 public function getStepHeaderHtml()
90 {
91 $multiStepSettings = $this->getFormInfoProperty('multiStepSettings');
92
93 if (isset($multiStepSettings->showStepHeader) && !$multiStepSettings->showStepHeader) {
94 return '';
95 }
96
97 $formID = $this->_form->getFormID();
98 $layout = $this->_layout;
99 $stepHeaderHtml = <<<HEADERHTML
100 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-hdr-cntnr")} _frm-b-stp-hdr-cntnr'>
101 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-hdr-wrpr")} _frm-b-stp-hdr-wrpr'>
102 HEADERHTML;
103
104 $showHeadarIcon = isset($multiStepSettings->headerIcon->show) ? $multiStepSettings->headerIcon->show : false;
105 $showLbl = isset($multiStepSettings->showLbl) ? $multiStepSettings->showLbl : false;
106 $showSubtitle = isset($multiStepSettings->showSubtitle) ? $multiStepSettings->showSubtitle : false;
107
108 $iconType = isset($multiStepSettings->headerIcon->iconType) ? $multiStepSettings->headerIcon->iconType : 'number';
109
110 $stepValidation = isset($multiStepSettings->validateOnStepChange) ? $multiStepSettings->validateOnStepChange : false;
111 foreach ($layout as $key => $lay) {
112 $step = $key + 1;
113 $settings = isset($lay->settings) ? $lay->settings : null;
114
115 if (empty($settings)) {
116 continue;
117 }
118 $iconWrapper = '';
119 $stepIcon = '';
120
121 if ('icon' === $iconType) {
122 $stepIcon = "<img src='{$settings->icon}' class={$this->_form->getAtomicCls("_frm-b{$formID}-stp-icn")} alt='Step Icon' />";
123 } else {
124 $stepIcon = "<span class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-num")}'>{$step}</span>";
125 }
126 if ($showHeadarIcon) {
127 $iconWrapper = <<<ICONWRPR
128 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-hdr-icn-wrp")} _frm-b-stp-hdr-icn-wrp'>
129 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-icn-cntn")} _frm-b-stp-icn-cntn'>
130 {$stepIcon}
131 </div>
132 </div>
133 ICONWRPR;
134 }
135 $showStepLbl = $showLbl && isset($settings->showLbl) ? $settings->showLbl : false;
136 $showStepSubtitle = $showSubtitle && isset($settings->showSubtitle) ? $settings->showSubtitle : false;
137 $lblPreIcn = isset($settings->lblPreIcn) ? $settings->lblPreIcn : null;
138 $lblSufIcn = isset($settings->lblSufIcn) ? $settings->lblSufIcn : null;
139 $subTlePreIcn = isset($settings->subTlePreIcn) ? $settings->subTlePreIcn : null;
140 $subTleSufIcn = isset($settings->subTleSufIcn) ? $settings->subTleSufIcn : null;
141 $stepLabelMarkup = $showStepLbl ? $this->getHeaderLabelMarkup($settings->lbl, $lblPreIcn, $lblSufIcn, 'lbl') : '';
142 $stepSubtitleMarkup = $showStepSubtitle ? $this->getHeaderLabelMarkup($settings->subtitle, $subTlePreIcn, $subTleSufIcn, 'sub-titl') : '';
143
144 $activeClass = 0 === $key ? 'active' : '';
145 $disableClass = (0 !== $key && $stepValidation) ? 'disabled' : '';
146 $stepHeaderHtml .= <<<HEADERHTML
147 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-hdr")} _frm-b-stp-hdr {$activeClass} {$disableClass}' data-step='{$step}'>
148 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-hdr-cntnt")} _frm-b-stp-hdr-cntnt'>
149 {$iconWrapper}
150 <span class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-hdr-titl-wrpr")} _frm-b-stp-hdr-titl-wrpr'>
151 {$stepLabelMarkup}
152 {$stepSubtitleMarkup}
153 </span>
154 </div>
155 </div>
156 HEADERHTML;
157 }
158 $stepHeaderHtml .= <<<HEADERHTML
159 </div>
160 </div>
161 HEADERHTML;
162 return $stepHeaderHtml;
163 }
164
165 public function getProgressBarMarkup()
166 {
167 $multiStepSettings = $this->getFormInfoProperty('multiStepSettings');
168 $progressBarSettings = isset($multiStepSettings->progressSettings) ? $multiStepSettings->progressSettings : null;
169 if (isset($progressBarSettings->show) && !$progressBarSettings->show) {
170 return '';
171 }
172 $precentage = (isset($progressBarSettings->showPercentage) && $progressBarSettings->showPercentage) ? '0%' : '';
173 $formID = $this->getFormId();
174 return <<<PROGRESSHTML
175 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-progress-wrpr")}'>
176 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-progress")}'>
177 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-progress-bar")}'>
178 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-progress-fill")}' style="width: 0%;">
179 {$precentage}
180 </div>
181 </div>
182 </div>
183 </div>
184 PROGRESSHTML;
185 }
186
187 public function getStepButtonMarkup()
188 {
189 $multiStepSettings = $this->getFormInfoProperty('multiStepSettings');
190 $btnSettings = isset($multiStepSettings->btnSettings) ? $multiStepSettings->btnSettings : null;
191 if (is_null($btnSettings) || (empty($btnSettings->show))) {
192 return '';
193 }
194 $formID = $this->getFormId();
195 return <<<BUTTONWRPR
196 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-btn-wrpr")}'>
197 <div class='{$this->_form->getAtomicCls("_frm-b{$formID}-stp-btn-cntnt")}'>
198 {$this->getStepButton($btnSettings->prevBtn)}
199 {$this->getStepButton($btnSettings->nextBtn)}
200 </div>
201 </div>
202 BUTTONWRPR;
203 }
204 }
205