1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anax\HTMLForm; |
4
|
|
|
|
5
|
|
|
use Psr\Container\ContainerInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Example of FormModel implementation. |
9
|
|
|
*/ |
10
|
|
|
class FormModelElementsHTML401 extends FormModel |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Constructor injects with DI container. |
14
|
|
|
* |
15
|
|
|
* @param Anax\DI\DIInterface $di a service container |
|
|
|
|
16
|
|
|
*/ |
17
|
|
|
public function __construct(ContainerInterface $di) |
18
|
|
|
{ |
19
|
|
|
parent::__construct($di); |
20
|
|
|
$this->form->create( |
21
|
|
|
[ |
22
|
|
|
"id" => __CLASS__, |
23
|
|
|
"legend" => "Legend", |
24
|
|
|
], |
25
|
|
|
[ |
26
|
|
|
"text" => [ |
27
|
|
|
"type" => "text", |
28
|
|
|
"description" => "Here you can place a description.", |
29
|
|
|
"placeholder" => "Here is a placeholder", |
30
|
|
|
], |
31
|
|
|
|
32
|
|
|
"password" => [ |
33
|
|
|
"type" => "password", |
34
|
|
|
"description" => "Here you can place a description.", |
35
|
|
|
"placeholder" => "Here is a placeholder", |
36
|
|
|
], |
37
|
|
|
|
38
|
|
|
"hidden" => [ |
39
|
|
|
"type" => "hidden", |
40
|
|
|
"value" => "secret value", |
41
|
|
|
], |
42
|
|
|
|
43
|
|
|
"file" => [ |
44
|
|
|
"type" => "file", |
45
|
|
|
"description" => "Here you can place a description.", |
46
|
|
|
], |
47
|
|
|
|
48
|
|
|
"textarea" => [ |
49
|
|
|
"type" => "textarea", |
50
|
|
|
"description" => "Here you can place a description.", |
51
|
|
|
"placeholder" => "Here is a placeholder", |
52
|
|
|
], |
53
|
|
|
|
54
|
|
|
"radio" => [ |
55
|
|
|
"type" => "radio", |
56
|
|
|
"label" => "What is your preferred choice of fruite?", |
57
|
|
|
"description" => "Here you can place a description.", |
58
|
|
|
"values" => [ |
59
|
|
|
"tomato", |
60
|
|
|
"potato", |
61
|
|
|
"apple", |
62
|
|
|
"pear", |
63
|
|
|
"banana" |
64
|
|
|
], |
65
|
|
|
"checked" => "potato", |
66
|
|
|
], |
67
|
|
|
|
68
|
|
|
"checkbox" => [ |
69
|
|
|
"type" => "checkbox", |
70
|
|
|
"description" => "Here you can place a description.", |
71
|
|
|
], |
72
|
|
|
|
73
|
|
|
"select" => [ |
74
|
|
|
"type" => "select", |
75
|
|
|
"label" => "Select your fruite:", |
76
|
|
|
"description" => "Here you can place a description.", |
77
|
|
|
"options" => [ |
78
|
|
|
"tomato" => "tomato", |
79
|
|
|
"potato" => "potato", |
80
|
|
|
"apple" => "apple", |
81
|
|
|
"pear" => "pear", |
82
|
|
|
"banana" => "banana", |
83
|
|
|
], |
84
|
|
|
"value" => "potato", |
85
|
|
|
], |
86
|
|
|
|
87
|
|
|
"selectm" => [ |
88
|
|
|
"type" => "select-multiple", |
89
|
|
|
"label" => "Select one or more fruite:", |
90
|
|
|
"description" => "Here you can place a description.", |
91
|
|
|
"size" => 6, |
92
|
|
|
"options" => [ |
93
|
|
|
"tomato" => "tomato", |
94
|
|
|
"potato" => "potato", |
95
|
|
|
"apple" => "apple", |
96
|
|
|
"pear" => "pear", |
97
|
|
|
"banana" => "banana", |
98
|
|
|
], |
99
|
|
|
"checked" => ["potato", "pear"], |
100
|
|
|
], |
101
|
|
|
|
102
|
|
|
"reset" => [ |
103
|
|
|
"type" => "reset", |
104
|
|
|
], |
105
|
|
|
|
106
|
|
|
"button" => [ |
107
|
|
|
"type" => "button", |
108
|
|
|
], |
109
|
|
|
|
110
|
|
|
"submit" => [ |
111
|
|
|
"type" => "submit", |
112
|
|
|
"value" => "Submit", |
113
|
|
|
"callback" => [$this, "callbackSubmit"] |
114
|
|
|
], |
115
|
|
|
] |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Callback for submit-button which should return true if it could |
123
|
|
|
* carry out its work and false if something failed. |
124
|
|
|
* |
125
|
|
|
* @return boolean true if okey, false if something went wrong. |
126
|
|
|
*/ |
127
|
|
|
public function callbackSubmit() |
128
|
|
|
{ |
129
|
|
|
// These return a single value |
130
|
|
|
// Type checkbox returns true if checked |
131
|
|
|
$elements = [ |
132
|
|
|
"text", "password", "hidden", "file", "textarea", "select", |
133
|
|
|
"radio", "checkbox", |
134
|
|
|
]; |
135
|
|
|
foreach ($elements as $name) { |
136
|
|
|
$this->form->addOutput( |
137
|
|
|
"$name has value: " |
138
|
|
|
. $this->form->value($name) |
139
|
|
|
. "</br>" |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
// Select multiple returns an array |
144
|
|
|
$elements = [ |
145
|
|
|
"selectm", |
146
|
|
|
]; |
147
|
|
|
foreach ($elements as $name) { |
148
|
|
|
$this->form->addOutput( |
149
|
|
|
"$name has value: " |
150
|
|
|
. implode($this->form->value($name), ", ") |
|
|
|
|
151
|
|
|
. "</br>" |
152
|
|
|
); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
// Remember values during resubmit, useful when failing (retunr false) |
156
|
|
|
// and asking the user to resubmit the form. |
157
|
|
|
$this->form->rememberValues(); |
158
|
|
|
|
159
|
|
|
return true; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths