1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anax\HTMLForm; |
4
|
|
|
|
5
|
|
|
use Psr\Container\ContainerInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Example of FormModel implementation. |
9
|
|
|
*/ |
10
|
|
|
class FormModelStyle 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
|
|
|
//"class" => "htmlform class1 class2", |
24
|
|
|
//"use_fieldset" => false, |
25
|
|
|
"legend" => "Legend", |
26
|
|
|
//"wrapper-element" => "div", |
27
|
|
|
//"br-after-label" => true, |
28
|
|
|
], |
29
|
|
|
[ |
30
|
|
|
"text" => [ |
31
|
|
|
"type" => "text", |
32
|
|
|
"description" => "Here you can place a description.", |
33
|
|
|
"placeholder" => "Here is a placeholder", |
34
|
|
|
//"wrapper-element" => "div", |
35
|
|
|
//"wrapper-class" => "wclass", |
36
|
|
|
//"class" => "specific", |
37
|
|
|
//"br-after-label" => false, |
38
|
|
|
], |
39
|
|
|
|
40
|
|
|
"password" => [ |
41
|
|
|
"type" => "password", |
42
|
|
|
"description" => "Here you can place a description.", |
43
|
|
|
"placeholder" => "Here is a placeholder", |
44
|
|
|
], |
45
|
|
|
|
46
|
|
|
"hidden" => [ |
47
|
|
|
"type" => "hidden", |
48
|
|
|
"value" => "secret value", |
49
|
|
|
], |
50
|
|
|
|
51
|
|
|
"file" => [ |
52
|
|
|
"type" => "file", |
53
|
|
|
"description" => "Here you can place a description.", |
54
|
|
|
], |
55
|
|
|
|
56
|
|
|
"textarea" => [ |
57
|
|
|
"type" => "textarea", |
58
|
|
|
"description" => "Here you can place a description.", |
59
|
|
|
"placeholder" => "Here is a placeholder", |
60
|
|
|
], |
61
|
|
|
|
62
|
|
|
"radio" => [ |
63
|
|
|
"type" => "radio", |
64
|
|
|
"label" => "What is your preferred choice of fruite?", |
65
|
|
|
"description" => "Here you can place a description.", |
66
|
|
|
"values" => [ |
67
|
|
|
"tomato", |
68
|
|
|
"potato", |
69
|
|
|
"apple", |
70
|
|
|
"pear", |
71
|
|
|
"banana" |
72
|
|
|
], |
73
|
|
|
"checked" => "potato", |
74
|
|
|
], |
75
|
|
|
|
76
|
|
|
"checkbox" => [ |
77
|
|
|
"type" => "checkbox", |
78
|
|
|
"description" => "Here you can place a description.", |
79
|
|
|
], |
80
|
|
|
|
81
|
|
|
"select" => [ |
82
|
|
|
"type" => "select", |
83
|
|
|
"label" => "Select your fruite:", |
84
|
|
|
"description" => "Here you can place a description.", |
85
|
|
|
"options" => [ |
86
|
|
|
"tomato" => "tomato", |
87
|
|
|
"potato" => "potato", |
88
|
|
|
"apple" => "apple", |
89
|
|
|
"pear" => "pear", |
90
|
|
|
"banana" => "banana", |
91
|
|
|
], |
92
|
|
|
"value" => "potato", |
93
|
|
|
], |
94
|
|
|
|
95
|
|
|
"selectm" => [ |
96
|
|
|
"type" => "select-multiple", |
97
|
|
|
"label" => "Select one or more fruite:", |
98
|
|
|
"description" => "Here you can place a description.", |
99
|
|
|
"size" => 6, |
100
|
|
|
"options" => [ |
101
|
|
|
"tomato" => "tomato", |
102
|
|
|
"potato" => "potato", |
103
|
|
|
"apple" => "apple", |
104
|
|
|
"pear" => "pear", |
105
|
|
|
"banana" => "banana", |
106
|
|
|
], |
107
|
|
|
"checked" => ["potato", "pear"], |
108
|
|
|
], |
109
|
|
|
|
110
|
|
|
"reset" => [ |
111
|
|
|
"type" => "reset", |
112
|
|
|
], |
113
|
|
|
|
114
|
|
|
"button" => [ |
115
|
|
|
"type" => "button", |
116
|
|
|
"onclick" => "alert('hej');" |
117
|
|
|
], |
118
|
|
|
|
119
|
|
|
"submit" => [ |
120
|
|
|
"type" => "submit", |
121
|
|
|
"value" => "Submit", |
122
|
|
|
"callback" => [$this, "callbackSubmit"] |
123
|
|
|
], |
124
|
|
|
] |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Callback for submit-button which should return true if it could |
132
|
|
|
* carry out its work and false if something failed. |
133
|
|
|
* |
134
|
|
|
* @return boolean true if okey, false if something went wrong. |
135
|
|
|
*/ |
136
|
|
|
public function callbackSubmit() |
137
|
|
|
{ |
138
|
|
|
// These return a single value |
139
|
|
|
// Type checkbox returns true if checked |
140
|
|
|
$elements = [ |
141
|
|
|
"text", "password", "hidden", "file", "textarea", "select", |
142
|
|
|
"radio", "checkbox", |
143
|
|
|
]; |
144
|
|
|
foreach ($elements as $name) { |
145
|
|
|
$this->form->addOutput( |
146
|
|
|
"$name has value: " |
147
|
|
|
. $this->form->value($name) |
148
|
|
|
. "</br>" |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
// Select multiple returns an array |
153
|
|
|
$elements = [ |
154
|
|
|
"selectm", |
155
|
|
|
]; |
156
|
|
|
foreach ($elements as $name) { |
157
|
|
|
$this->form->addOutput( |
158
|
|
|
"$name has value: " |
159
|
|
|
. implode($this->form->value($name), ", ") |
|
|
|
|
160
|
|
|
. "</br>" |
161
|
|
|
); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
// Set <output> class |
165
|
|
|
$this->form->setOutputClass("info"); |
166
|
|
|
|
167
|
|
|
// Remember values during resubmit, useful when failing (retunr false) |
168
|
|
|
// and asking the user to resubmit the form. |
169
|
|
|
$this->form->rememberValues(); |
170
|
|
|
|
171
|
|
|
return true; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
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