PluginProbe
Contact Forms by Cimatti / 2.1.2
Contact Forms by Cimatti v2.1.2
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / classes / View / Standard.php

Standard.php in Contact Forms by Cimatti 2.1.2, at classes/View/Standard.php

117 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- PFBC View class, HTML output is controlled
3 class AccuaForm_View_Standard extends View {
4 public function render() {
5 echo '<form', $this->form->getAttributes(), '>';
6 $this->form->getError()->render();
7
8 $elements = $this->form->getElements();
9 $elementCount = 0;
10 $inButtonGroup = false;
11
12 foreach($elements as $element) {
13 if($element instanceof Element_Hidden || $element instanceof Element_HTMLExternal) {
14 $element->render();
15 } elseif($element instanceof Element_Button) {
16 if (!$inButtonGroup) {
17 echo '<div class="pfbc-element pfbc-buttons">';
18 $inButtonGroup = true;
19 }
20 $element->render();
21 } else {
22 if ($inButtonGroup) {
23 echo '</div>';
24 $inButtonGroup = false;
25 }
26 if ($element instanceof AccuaForm_Element_FieldsetBegin || $element instanceof AccuaForm_Element_FieldsetEnd) {
27 $element->render();
28 } else {
29 echo '<div class="pfbc-element-', $elementCount, ' pfbc-element';
30 if($element->hasErrors()) {
31 echo ' pfbc-element-has-error';
32 }
33 $_wrapperClass = $element->getWrapperCssClass();
34 if(!empty($_wrapperClass)) {
35 echo ' ', esc_attr($_wrapperClass);
36 }
37 echo '"';
38 $_wrapperId = $element->getWrapperCssId();
39 if(!empty($_wrapperId)) {
40 echo ' id="', esc_attr($_wrapperId), '"';
41 }
42 echo '>', $element->getPreHTML();
43 $this->renderLabel($element);
44 if ($element instanceof Element_HTML) {
45 $element->render();
46 } else {
47 echo '<div class="pfbc-fieldwrap">';
48 $element->render();
49 echo '</div>';
50 $this->renderInlineError($element);
51 }
52 echo $element->getPostHTML(), '<div class="pfbc-elementbottom"></div></div>';
53 ++$elementCount;
54 }
55 }
56 }
57
58 if ($inButtonGroup) {
59 echo '</div>';
60 $inButtonGroup = false;
61 }
62
63 echo '</form>';
64 }
65
66 /*This method encapsulates the various pieces that are included in an element's label.*/
67 protected function renderLabel($element) {
68 $label = $element->getLabel();
69 $id = $element->getID();
70 $description = $element->getDescription();
71 if(!empty($label) || !empty($description)) {
72 echo '<div class="pfbc-label">';
73 if(!empty($label)) {
74 echo '<label for="', $id, '">', $label;
75 if($element->isRequired())
76 echo ' <span class="pfbc-required" aria-label="required">*</span>';
77 echo '</label>';
78 }
79 if(!empty($description))
80 echo '<em>', $description, '</em>';
81 echo '</div>';
82 }
83 }
84
85 public function renderCSS() {
86 $id = $this->form->getId();
87 $width = $this->form->getWidth();
88 $widthSuffix = $this->form->getWidthSuffix();
89 $this->form->renderCSS();
90 /*
91 parent::renderCSS();
92 echo <<<CSS
93 #$id { width: $width{$widthSuffix}; }
94 #$id .pfbc-element { margin-bottom: .6em }
95 #$id .pfbc-label { margin-bottom: .2em; }
96 #$id .pfbc-label label { display: block; }
97 #$id .pfbc-textbox, #$id .pfbc-textarea, #$id .pfbc-select { width: 98% !important; display:block; border: 1px solid #ccc; padding:2px; }
98 #$id .pfbc-fieldwrap { width: $width{$widthSuffix}; display: inline-block; }
99 #$id .pfbc-buttons { text-align: right; }
100 CSS;
101
102 $elements = $this->form->getElements();
103 $elementCount = 0;
104 foreach ($elements as $element) {
105 $elementWidth = $element->getWidth();
106 if(!$element instanceof Element_Hidden && !$element instanceof Element_HTMLExternal && !$element instanceof Element_HTMLExternal) {
107 if(!empty($elementWidth)) {
108 echo '#', $id, ' .pfbc-element-', $elementCount, ' { width: ', $elementWidth, $widthSuffix, '; }';
109 echo '#', $id, ' .pfbc-element-', $elementCount, ' .pfbc-textbox, #', $id, ' .pfbc-element-', $elementCount, ' .pfbc-textarea, #', $id, ' .pfbc-element-', $elementCount, ' .pfbc-select { width: ', $elementWidth, $widthSuffix, '; }';
110 }
111 $elementCount++;
112 }
113 } */
114
115 }
116 }
117