PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.9
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.9
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.9, at includes/Frontend/Form/View/FormViewer.php

115 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;
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 = isset($form_contents->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(' ', '', $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 if ($this->_fields->{$row->i}->typ === 'button' && $this->_fields->{$row->i}->btnTyp === 'submit') {
58 $field_name = $formIdentifier;
59 }
60 // $field_name .= isset($this->_fields->{$row->i}->lbl) ? preg_replace('/[\`\~\!\@\#\$\'\.\s\?\+\-\*\&\|\/\\\!]/', '_', $this->_fields->{$row->i}->lbl) : "";
61 $error = isset($this->_error[$field_name]) ? $this->_error[$field_name] : null;
62 $valueToEsc = isset($this->_previousValue[$field_name]) ?
63 $this->_previousValue[$field_name] : (isset($this->_fields->{$row->i}->val) ? $this->_fields->{$row->i}->val : null);
64 if (empty($valueToEsc)) {
65 $value = null;
66 } else {
67 if ((isset($this->_fields->{$row->i}->mul) || $this->_fields->{$row->i}->typ === 'check' || $this->_fields->{$row->i}->typ === 'select')) {
68 if ($this->_fields->{$row->i}->typ === 'select' && is_string($valueToEsc)) {
69 $valueToEsc = explode(',', $valueToEsc);
70 }
71 if (is_array($valueToEsc)) {
72 $value = array_map('esc_attr', $valueToEsc);
73 } else {
74 $value = esc_attr($valueToEsc);
75 }
76 } else {
77 $value = !is_array($valueToEsc) ? esc_attr($valueToEsc) :
78 esc_attr($valueToEsc[count($valueToEsc) - 1]);
79 }
80 }
81
82 $fieldHtml .= $this->_themeDetails->inputWrapper(
83 $this->_fields->{$row->i},
84 $row->i,
85 $field_name,
86 $error,
87 $value,
88 $formID
89 );
90 }
91
92 if (!empty($this->_buttons)) {
93 $this->_buttons->name = $formIdentifier;
94 $buttonClass = "button-{$formIdentifier}";
95 $subBtn = $this->_themeDetails->getField($this->_buttons, $buttonClass, '');
96 }
97
98 $formHTML =
99 <<<FORM
100 <div id="f-{$formID}">
101 <form novalidate id="form-{$formIdentifier}" class="_frm-bg-{$formID}" action="" $file_upload_tag method='post'>
102 <input type="hidden" name="bitforms_token" value="{$this->_form->getFormToken()}">
103 <input type="hidden" name="bitforms_id" value="bitforms_{$this->_form->getFormID()}">
104 <div class="_frm-{$formID}">
105 <div class="_frm-g _frm-g-{$formID}">
106 $fieldHtml
107 </div>
108 </div>
109 </form>
110 </div>
111 FORM;
112 return $formHTML;
113 }
114 }
115