PluginProbe
Contact Forms by Cimatti / 1.9.2
Contact Forms by Cimatti v1.9.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
← All changes | PFBC/Element.php +4 -75 2.3.51.9.2 View file →
@@ -1,14 +1,7 @@
1 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, WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput, WordPress.WP.AlternativeFunctions, WordPress.PHP.DevelopmentFunctions -- Third-party library
8 -
9 2 abstract class Element extends Base {
10 - protected $errors = array();
3 + private $errors = array();
11 4
12 5 protected $attributes;
13 6 protected $form;
14 7 protected $label;
@@ -16,12 +9,10 @@
16 9 protected $validation = array();
17 10 protected $preHTML;
18 11 protected $postHTML;
19 12 protected $width;
20 - protected $wrapperCssClass;
21 - protected $wrapperCssId;
22 13
23 - public function __construct($label, $name, ?array $properties = null) {
14 + public function __construct($label, $name, array $properties = null) {
24 15 $configuration = array(
25 16 "label" => $label,
26 17 "name" => $name
27 18 );
@@ -36,9 +27,9 @@
36 27
37 28 /*When an element is serialized and stored in the session, this method prevents any non-essential
38 29 information from being included.*/
39 30 public function __sleep() {
40 - return array("attributes", "label", "validation", "errors");
31 + return array("attributes", "label", "validation");
41 32 }
42 33
43 34 /*If an element requires external stylesheets, this method is used to return an
44 35 array of entries that will be applied before the form is rendered.*/
@@ -49,30 +40,10 @@
49 40 }
50 41
51 42 public function getErrors() {
52 43 return $this->errors;
53 - }
44 + }
54 45
55 - /*Set errors on the element (used for accessibility when re-rendering after validation)*/
56 - public function setErrors($errors) {
57 - if(is_array($errors)) {
58 - $this->errors = $errors;
59 - }
60 - }
61 -
62 - /*Get the error container ID for this element (for aria-describedby)*/
63 - public function getErrorID() {
64 - $id = $this->getID();
65 - if(!empty($id))
66 - return $id . '-error';
67 - return '';
68 - }
69 -
70 - /*Check if element has validation errors*/
71 - public function hasErrors() {
72 - return !empty($this->errors);
73 - }
74 -
75 46 public function getID() {
76 47 if(!empty($this->attributes["id"]))
77 48 return $this->attributes["id"];
78 49 else
@@ -105,16 +76,8 @@
105 76 public function getWidth() {
106 77 return $this->width;
107 78 }
108 79
109 - public function getWrapperCssClass() {
110 - return $this->wrapperCssClass;
111 - }
112 -
113 - public function getWrapperCssId() {
114 - return $this->wrapperCssId;
115 - }
116 -
117 80 /*This method provides a shortcut for checking if an element is required.*/
118 81 public function isRequired() {
119 82 if(!empty($this->validation)) {
120 83 foreach($this->validation as $validation) {
@@ -137,10 +100,8 @@
137 100 }
138 101 else
139 102 $element = $this->attributes["name"];
140 103
141 - $this->errors = array();
142 -
143 104 foreach($this->validation as $validation) {
144 105 if(!$validation->isValid($value)) {
145 106 /*In the error message, %element% will be replaced by the element's label (or
146 107 name if label is not provided).*/
@@ -175,44 +136,12 @@
175 136 echo "{ ", $options, " }";
176 137 }
177 138 }
178 139
179 - /*Apply ARIA attributes for accessibility*/
180 - public function applyAriaAttributes() {
181 - // Add required attribute and aria-required for required fields (W3C/EAA compliance)
182 - if($this->isRequired()) {
183 - if(!isset($this->attributes['required'])) {
184 - $this->attributes['required'] = 'required';
185 - }
186 - if(!isset($this->attributes['aria-required'])) {
187 - $this->attributes['aria-required'] = 'true';
188 - }
189 - }
190 -
191 - // Add aria-invalid if field has errors
192 - if($this->hasErrors() && !isset($this->attributes['aria-invalid'])) {
193 - $this->attributes['aria-invalid'] = 'true';
194 - }
195 -
196 - // Add aria-describedby for error association
197 - $errorID = $this->getErrorID();
198 - if($this->hasErrors() && !empty($errorID)) {
199 - if(!empty($this->attributes['aria-describedby'])) {
200 - // Append to existing aria-describedby
201 - if(strpos($this->attributes['aria-describedby'], $errorID) === false) {
202 - $this->attributes['aria-describedby'] .= ' ' . $errorID;
203 - }
204 - } else {
205 - $this->attributes['aria-describedby'] = $errorID;
206 - }
207 - }
208 - }
209 -
210 140 /*Many of the included elements make use of the <input> tag for display. These include the Hidden, Textbox,
211 141 Password, Date, Color, Button, Email, and File element classes. The project's other element classes will
212 142 override this method with their own implementation.*/
213 143 public function render() {
214 - $this->applyAriaAttributes();
215 144 echo '<input', $this->getAttributes(), '/>';
216 145 }
217 146
218 147 /*If an element requires inline stylesheet definitions, this method is used send them to the browser before