PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.1.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.1.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 2.10.2 All 137 releases
bit-form / includes / Frontend / Form / View / FormViewer.php

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

111 lines 4.1 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 FormViewer
8 {
9 private $_theme = 'Default';
10 private $_themeDetails;
11 private $_fields;
12 private $_layout;
13 private $_buttons;
14 private $_form;
15 private $_error;
16 private $_previousValue;
17 public function __construct(FrontendFormManager $formManager, $form_contents, $errorMessages = null, $previousValue = null)
18 {
19 $this->_fields = $form_contents->fields;
20 $this->_layout = $form_contents->layout;
21 $this->_buttons = $form_contents->buttons;
22 $this->_form = $formManager;
23 $this->_error = $errorMessages;
24 $this->_previousValue = $previousValue;
25 }
26 public function getView($hasFile)
27 {
28 $name = str_replace(' ', null, $this->_theme);
29 $file = strpos($name, 'Theme') !== false ? $name . '.php' : $name . 'Theme.php';
30 if (file_exists(__DIR__ . '/' . $file)) {
31 $className = __NAMESPACE__ . '\\Theme\\' . $name . 'Theme';
32 $this->_themeDetails = new $className;
33 } else {
34 $className = __NAMESPACE__ . '\\Theme\\' . 'DefaultTheme';
35 $this->_themeDetails = new $className;
36 }
37 return $this->setView($hasFile);
38 }
39
40 public function setTheme($theme = 'Default')
41 {
42 $this->_theme = $theme;
43 }
44
45 private function setView($hasFile)
46 {
47 $file_upload_tag = null;
48 $formID = $this->_form->getFormID();
49 if ($hasFile) {
50 $file_upload_tag = 'enctype="multipart/form-data"';
51 wp_enqueue_script('bitforms-frontend-file');
52 }
53 $formIdentifier = $this->_form->getFormIdentifier();
54 $fieldHtml = "";
55 foreach ($this->_layout->lg as $key => $row) {
56 $field_name = $row->i;
57 // $field_name .= isset($this->_fields->{$row->i}->lbl) ? preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\\!]/', '_', $this->_fields->{$row->i}->lbl) : "";
58 $error = isset($this->_error[$field_name]) ? $this->_error[$field_name] : null;
59 $valueToEsc = isset($this->_previousValue[$field_name]) ?
60 $this->_previousValue[$field_name] : (isset($this->_fields->{$row->i}->val) ? $this->_fields->{$row->i}->val : null);
61 if (empty($valueToEsc)) {
62 $value = null;
63 } else {
64 if ((isset($this->_fields->{$row->i}->mul) || $this->_fields->{$row->i}->typ === 'check' || $this->_fields->{$row->i}->typ === 'select')) {
65 if ($this->_fields->{$row->i}->typ === 'select' && is_string($valueToEsc)) {
66 $valueToEsc = explode(',', $valueToEsc);
67 }
68 if (is_array($valueToEsc)) {
69 $value = array_map('esc_attr', $valueToEsc);
70 } else {
71 $value = esc_attr($valueToEsc);
72 }
73 } else {
74 $value = !is_array($valueToEsc) ? esc_attr($valueToEsc) :
75 esc_attr($valueToEsc[count($valueToEsc) - 1]);
76 }
77 }
78
79 $fieldHtml .= $this->_themeDetails->getField(
80 $this->_fields->{$row->i},
81 $row->i,
82 $field_name,
83 $error,
84 $value,
85 $formID
86 );
87 }
88
89 $this->_buttons->name = $formIdentifier;
90 $buttonClass = "button-{$formIdentifier}";
91 $subBtn = $this->_themeDetails->getField($this->_buttons, $buttonClass, '');
92
93 $formHTML =
94 <<<FORM
95 <div id="f-{$formID}">
96 <form id="form-{$formIdentifier}" class="_frm-bg-{$formID}" action="" $file_upload_tag method='post'>
97 <input type="hidden" name="bitforms_token" value="{$this->_form->getFormToken()}">
98 <input type="hidden" name="bitforms_id" value="bitforms_{$this->_form->getFormID()}">
99 <div class="_frm-{$formID}">
100 <div class="_frm-g _frm-g-{$formID}">
101 $fieldHtml
102 </div>
103 </div>
104 $subBtn
105 </form>
106 </div>
107 FORM;
108 return $formHTML;
109 }
110 }
111