PluginProbe
Contact Forms by Cimatti / 2.2.32
Contact Forms by Cimatti v2.2.32
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 / PFBC / View.php

View.php in Contact Forms by Cimatti 2.2.32, at PFBC/View.php

77 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PFBC (PHP Form Builder Class) - Third-party library
4 * @package PFBC
5 */
6
7 // phpcs:disable WordPress.Security.EscapeOutput, WordPress.NamingConventions.PrefixAllGlobals, PluginCheck.CodeAnalysis.Heredoc -- Third-party library
8
9 abstract class View extends Base {
10 protected $form;
11
12 public function __construct(?array $properties = null) {
13 $this->configure($properties);
14 }
15
16 /*This method encapsulates the various pieces that are included in an element's label.*/
17 protected function renderLabel($element) {
18 $label = $element->getLabel();
19 $id = $element->getID();
20 $description = $element->getDescription();
21 if(!empty($label) || !empty($description)) {
22 echo '<div class="pfbc-label">';
23 if(!empty($label)) {
24 echo '<label for="', $id, '">';
25 if($element->isRequired())
26 echo '<span class="pfbc-required" aria-label="required">*</span> ';
27 echo $label, '</label>';
28 }
29 if(!empty($description))
30 echo '<em>', $description, '</em>';
31 echo '</div>';
32 }
33 }
34
35 /*Render inline error messages for an element with proper ARIA support*/
36 protected function renderInlineError($element) {
37 $errors = $element->getErrors();
38 $errorID = $element->getErrorID();
39 if(!empty($errors) && !empty($errorID)) {
40 echo '<div class="pfbc-inline-error" id="', $errorID, '" role="alert" aria-live="polite">';
41 echo '<span class="pfbc-error-icon" aria-hidden="true">⚠</span> ';
42 echo '<span class="pfbc-error-text">', implode(' ', $errors), '</span>';
43 echo '</div>';
44 }
45 }
46
47 public function setForm(Form $form) {
48 $this->form = $form;
49 }
50
51 /*jQuery is used to apply css entries to the last element.*/
52 public function jQueryDocumentReady() {
53 echo 'jQuery("#', $this->form->getId(), ' .pfbc-element:last").css({ "margin-bottom": "0", "padding-bottom": "0", "border-bottom": "none" });';
54 }
55
56 public function render() {}
57
58 public function renderCSS() {
59 $id = $this->form->getId();
60
61 /*For ease-of-use, default styles are applied to form elements.*/
62 if(!in_array("style", $this->form->getPrevent())) {
63 echo <<<CSS
64 #$id .pfbc-label label { font-weight: bold; }
65 #$id .pfbc-label em { font-size: .9em; color: #888; }
66 #$id .pfbc-label strong { color: #990000; }
67 #$id .pfbc-textbox, #$id .pfbc-textarea, #$id .pfbc-select { border: 1px solid #ccc; font-size: 14px; }
68 #$id .pfbc-textbox, #$id .pfbc-textarea { padding: 7px; }
69 #$id .pfbc-select { padding: 6px 7px; }
70 #$id img.pfbc-loading { position: absolute; top: 50%; right: .5em; margin-top: -8px; border: 0; }
71 CSS;
72 }
73 }
74
75 public function renderJS() {}
76 }
77