File tree Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ The package has no dependencies on other packages.
25
25
Then add the following to alias the most used classes in your PHP file:
26
26
27
27
``` php
28
- use MintyPHP\Forms \Elements as E;
29
- use MintyPHP\Forms\Elements as V;
28
+ use MintyPHP\Form \Elements as E;
29
+ use MintyPHP\Form\Validator\Validators as V;
30
30
```
31
31
32
32
Create a simple login form using:
@@ -112,6 +112,8 @@ A Full Contact Form using Bulma
112
112
// include MintyPHP Forms
113
113
require_once 'vendor/autoload.php';
114
114
115
+ // alias the classes
116
+
115
117
// set style to Bulma
116
118
117
119
// create a form object
Original file line number Diff line number Diff line change @@ -153,6 +153,16 @@ public function validate(): bool
153
153
return $ isValid ;
154
154
}
155
155
156
+ /**
157
+ * @param array<string, string> $messages
158
+ */
159
+ public function setErrors (array $ messages ): void
160
+ {
161
+ foreach ($ this ->fieldsets as $ fieldset ) {
162
+ $ fieldset ->setErrors ($ messages );
163
+ }
164
+ }
165
+
156
166
public function renderDom (\DOMDocument $ doc ): \DOMElement
157
167
{
158
168
// Create a new DOMElement for the form
Original file line number Diff line number Diff line change @@ -63,6 +63,11 @@ public function control(FormControl $control): self
63
63
return $ this ;
64
64
}
65
65
66
+ public function getControl (): ?FormControl
67
+ {
68
+ return $ this ->control ;
69
+ }
70
+
66
71
/**
67
72
* @param Validator[] $validators
68
73
*/
Original file line number Diff line number Diff line change @@ -89,9 +89,17 @@ public function validate(): bool
89
89
return $ isValid ;
90
90
}
91
91
92
- public function setError (string $ message ): void
92
+ /**
93
+ * @param array<string, string> $messages
94
+ */
95
+ public function setErrors (array $ messages ): void
93
96
{
94
97
foreach ($ this ->fields as $ field ) {
98
+ $ name = $ field ->getControl ()->getName ();
99
+ if (!isset ($ messages [$ name ])) {
100
+ continue ;
101
+ }
102
+ $ message = $ messages [$ name ];
95
103
$ field ->setError ($ message );
96
104
}
97
105
}
You can’t perform that action at this time.
0 commit comments