|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Iriven France |
|
5
|
|
|
* Date: 08/05/2018 |
|
6
|
|
|
* Time: 16:25 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Iriven\Plugins\Form; |
|
10
|
|
|
use \Iriven\Plugins\Form\Core\Libs\Collection; |
|
|
|
|
|
|
11
|
|
|
use \Iriven\Plugins\Form\Elements\Audio; |
|
|
|
|
|
|
12
|
|
|
use \Iriven\Plugins\Form\Elements\Button; |
|
|
|
|
|
|
13
|
|
|
use \Iriven\Plugins\Form\Elements\Captcha; |
|
|
|
|
|
|
14
|
|
|
use \Iriven\Plugins\Form\Elements\Checkbox; |
|
|
|
|
|
|
15
|
|
|
use \Iriven\Plugins\Form\Elements\Color; |
|
|
|
|
|
|
16
|
|
|
use \Iriven\Plugins\Form\Elements\Country; |
|
|
|
|
|
|
17
|
|
|
use \Iriven\Plugins\Form\Elements\Datalist; |
|
|
|
|
|
|
18
|
|
|
use \Iriven\Plugins\Form\Elements\Date; |
|
|
|
|
|
|
19
|
|
|
use \Iriven\Plugins\Form\Elements\Datetime; |
|
|
|
|
|
|
20
|
|
|
use \Iriven\Plugins\Form\Elements\DatetimeLocal; |
|
|
|
|
|
|
21
|
|
|
use \Iriven\Plugins\Form\Elements\Editor; |
|
|
|
|
|
|
22
|
|
|
use \Iriven\Plugins\Form\Elements\Email; |
|
|
|
|
|
|
23
|
|
|
use \Iriven\Plugins\Form\Elements\File; |
|
|
|
|
|
|
24
|
|
|
use \Iriven\Plugins\Form\Elements\Hidden; |
|
|
|
|
|
|
25
|
|
|
use \Iriven\Plugins\Form\Elements\Image; |
|
|
|
|
|
|
26
|
|
|
use \Iriven\Plugins\Form\Elements\Month; |
|
|
|
|
|
|
27
|
|
|
use \Iriven\Plugins\Form\Elements\Number; |
|
|
|
|
|
|
28
|
|
|
use \Iriven\Plugins\Form\Elements\Password; |
|
|
|
|
|
|
29
|
|
|
use \Iriven\Plugins\Form\Elements\Phone; |
|
|
|
|
|
|
30
|
|
|
use \Iriven\Plugins\Form\Elements\Radio; |
|
|
|
|
|
|
31
|
|
|
use \Iriven\Plugins\Form\Elements\Range; |
|
|
|
|
|
|
32
|
|
|
use \Iriven\Plugins\Form\Elements\Reset; |
|
|
|
|
|
|
33
|
|
|
use \Iriven\Plugins\Form\Elements\Search; |
|
|
|
|
|
|
34
|
|
|
use \Iriven\Plugins\Form\Elements\Select; |
|
|
|
|
|
|
35
|
|
|
use \Iriven\Plugins\Form\Elements\Submit; |
|
|
|
|
|
|
36
|
|
|
use \Iriven\Plugins\Form\Elements\Text; |
|
|
|
|
|
|
37
|
|
|
use \Iriven\Plugins\Form\Elements\Textarea; |
|
|
|
|
|
|
38
|
|
|
use \Iriven\Plugins\Form\Elements\Time; |
|
|
|
|
|
|
39
|
|
|
use \Iriven\Plugins\Form\Elements\Url; |
|
|
|
|
|
|
40
|
|
|
use \Iriven\Plugins\Form\Elements\Video; |
|
|
|
|
|
|
41
|
|
|
use \Iriven\Plugins\Form\Elements\Week; |
|
|
|
|
|
|
42
|
|
|
use \Iriven\Plugins\Form\Elements\YesNo; |
|
|
|
|
|
|
43
|
|
|
use \Iriven\Plugins\Form\Core\fieldsetGenerator; |
|
|
|
|
|
|
44
|
|
|
use \Iriven\Plugins\Form\Core\form; |
|
|
|
|
|
|
45
|
|
|
use \Iriven\Plugins\Form\Core\Libs\Traits\KeyNormalizer; |
|
|
|
|
|
|
46
|
|
|
use \Iriven\Plugins\Form\Core\FormElement; |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
class FormGenerator |
|
50
|
|
|
{ |
|
51
|
|
|
use KeyNormalizer; |
|
52
|
|
|
public $Errors; |
|
53
|
|
|
private $Form; |
|
54
|
|
|
private $Fieldset; |
|
55
|
|
|
private $Request; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* FormGenerator constructor. |
|
59
|
|
|
* |
|
60
|
|
|
* @param $App |
|
61
|
|
|
*/ |
|
62
|
|
|
public function __construct($App) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->Request = $App->Request(); |
|
65
|
|
|
$formErrors = $App->get('errors',[]); |
|
66
|
|
|
is_array($formErrors) OR $formErrors = [$formErrors]; |
|
67
|
|
|
$this->Errors = new Collection($formErrors); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param $label |
|
72
|
|
|
* @param array $attributes |
|
73
|
|
|
* @return $this |
|
74
|
|
|
*/ |
|
75
|
|
|
public function addAudio($label,$attributes=[]) |
|
76
|
|
|
{ |
|
77
|
|
|
if($this->Form instanceof form) |
|
78
|
|
|
{ |
|
79
|
|
|
$item = new Audio($label,$attributes); |
|
80
|
|
|
$item->Attributes()->set('accept','audio/*'); |
|
81
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
82
|
|
|
$this->Form->Attributes()->set('enctype','multipart/form-data'); |
|
83
|
|
|
$this->Form->append($item); |
|
84
|
|
|
} |
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param $label |
|
90
|
|
|
* @param array $attributes |
|
91
|
|
|
* @return $this |
|
92
|
|
|
*/ |
|
93
|
|
|
public function addButton($label,$attributes=[]) |
|
94
|
|
|
{ |
|
95
|
|
|
if($this->Form instanceof form) |
|
96
|
|
|
{ |
|
97
|
|
|
$item = new Button($label,$attributes); |
|
98
|
|
|
$this->Form->append($item); |
|
99
|
|
|
} |
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param $label |
|
105
|
|
|
* @param array $attributes |
|
106
|
|
|
* @return $this |
|
107
|
|
|
*/ |
|
108
|
|
|
public function addCaptcha($label,$attributes=[]) |
|
109
|
|
|
{ |
|
110
|
|
|
if($this->Form instanceof form) |
|
111
|
|
|
{ |
|
112
|
|
|
$item = new Captcha($label,$attributes); |
|
113
|
|
|
//$this->Request->getSession()->set(md5($item->Attributes()->get('name')), $item->Attributes()->get('capresponse')); |
|
114
|
|
|
// $this->Request->Session->set(md5($item->Attributes()->get('name')),$item->Attributes()->get('capresponse')); |
|
115
|
|
|
$this->Form->append($item); |
|
116
|
|
|
} |
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param $label |
|
122
|
|
|
* @param array $options |
|
123
|
|
|
* @param array $attributes |
|
124
|
|
|
* @return $this |
|
125
|
|
|
*/ |
|
126
|
|
|
public function addCheckbox($label,$options = [],$attributes=[]) |
|
127
|
|
|
{ |
|
128
|
|
|
if($this->Form instanceof form) |
|
129
|
|
|
{ |
|
130
|
|
|
$item = new Checkbox($label,$options ,$attributes); |
|
131
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
132
|
|
|
$this->Form->append($item); |
|
133
|
|
|
} |
|
134
|
|
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param $label |
|
139
|
|
|
* @param array $attributes |
|
140
|
|
|
* @return $this |
|
141
|
|
|
*/ |
|
142
|
|
|
public function addColor($label,$attributes=[]) |
|
143
|
|
|
{ |
|
144
|
|
|
if($this->Form instanceof form) |
|
145
|
|
|
{ |
|
146
|
|
|
$item = new Color($label,$attributes); |
|
147
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
148
|
|
|
$this->Form->append($item); |
|
149
|
|
|
} |
|
150
|
|
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param $label |
|
155
|
|
|
* @param array $attributes |
|
156
|
|
|
* @return $this |
|
157
|
|
|
*/ |
|
158
|
|
|
public function addCountries($label,$attributes=[]) |
|
159
|
|
|
{ |
|
160
|
|
|
if($this->Form instanceof form) |
|
161
|
|
|
{ |
|
162
|
|
|
$item = new Country($label,$attributes); |
|
163
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
164
|
|
|
$this->Form->append($item); |
|
165
|
|
|
} |
|
166
|
|
|
return $this; |
|
167
|
|
|
} |
|
168
|
|
|
/** |
|
169
|
|
|
* @param $label |
|
170
|
|
|
* @param array $attributes |
|
171
|
|
|
* @return $this |
|
172
|
|
|
*/ |
|
173
|
|
|
public function addDatalist($label, $options=[], $attributes = []) |
|
174
|
|
|
{ |
|
175
|
|
|
if ($this->Form instanceof form) { |
|
176
|
|
|
$item = new Datalist($label, $options, $attributes); |
|
177
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
178
|
|
|
$this->Form->append($item); |
|
179
|
|
|
} |
|
180
|
|
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param $label |
|
185
|
|
|
* @param array $attributes |
|
186
|
|
|
* @return $this |
|
187
|
|
|
*/ |
|
188
|
|
|
public function addDate($label,$attributes=[]) |
|
189
|
|
|
{ |
|
190
|
|
|
if($this->Form instanceof form) |
|
191
|
|
|
{ |
|
192
|
|
|
$item = new Date($label,$attributes); |
|
193
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
194
|
|
|
$this->Form->append($item); |
|
195
|
|
|
} |
|
196
|
|
|
return $this; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @param $label |
|
201
|
|
|
* @param array $attributes |
|
202
|
|
|
* @return $this |
|
203
|
|
|
*/ |
|
204
|
|
|
public function addDatetime($label,$attributes=[]) |
|
205
|
|
|
{ |
|
206
|
|
|
if($this->Form instanceof form) |
|
207
|
|
|
{ |
|
208
|
|
|
$item = new Datetime($label,$attributes); |
|
209
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
210
|
|
|
$this->Form->append($item); |
|
211
|
|
|
} |
|
212
|
|
|
return $this; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @param $label |
|
217
|
|
|
* @param array $attributes |
|
218
|
|
|
* @return $this |
|
219
|
|
|
*/ |
|
220
|
|
|
public function addDatetimeLocal($label,$attributes=[]) |
|
221
|
|
|
{ |
|
222
|
|
|
if($this->Form instanceof form) |
|
223
|
|
|
{ |
|
224
|
|
|
$item = new DatetimeLocal($label,$attributes); |
|
225
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
226
|
|
|
$this->Form->append($item); |
|
227
|
|
|
} |
|
228
|
|
|
return $this; |
|
229
|
|
|
} |
|
230
|
|
|
/** |
|
231
|
|
|
* @param $label |
|
232
|
|
|
* @param array $attributes |
|
233
|
|
|
* @return $this |
|
234
|
|
|
*/ |
|
235
|
|
|
public function addEditor($label,$attributes=[]) |
|
236
|
|
|
{ |
|
237
|
|
|
if($this->Form instanceof form) |
|
238
|
|
|
{ |
|
239
|
|
|
$item = new Editor($label,$attributes); |
|
240
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
241
|
|
|
$this->Form->append($item); |
|
242
|
|
|
} |
|
243
|
|
|
return $this; |
|
244
|
|
|
} |
|
245
|
|
|
/** |
|
246
|
|
|
* @param $label |
|
247
|
|
|
* @param array $attributes |
|
248
|
|
|
* @return $this |
|
249
|
|
|
*/ |
|
250
|
|
|
public function addEmail($label,$attributes=[]) |
|
251
|
|
|
{ |
|
252
|
|
|
if($this->Form instanceof form) |
|
253
|
|
|
{ |
|
254
|
|
|
$item = new Email($label,$attributes); |
|
255
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
256
|
|
|
$this->Form->append($item); |
|
257
|
|
|
} |
|
258
|
|
|
return $this; |
|
259
|
|
|
} |
|
260
|
|
|
/** |
|
261
|
|
|
* @param array $attributes |
|
262
|
|
|
* @return $this |
|
263
|
|
|
*/ |
|
264
|
|
|
public function addFieldset($attributes=[]) |
|
265
|
|
|
{ |
|
266
|
|
|
if($this->Form instanceof form) |
|
267
|
|
|
{ |
|
268
|
|
|
if($this->Fieldset instanceof fieldsetGenerator) |
|
269
|
|
|
$this->Form->append($this->Fieldset->Close()); |
|
270
|
|
|
$this->Fieldset = new fieldsetGenerator($attributes); |
|
271
|
|
|
$this->Fieldset->Attributes()->set('name', $this->Form->Attributes()->get('name')); |
|
272
|
|
|
$this->Form->append($this->Fieldset->Open()); |
|
273
|
|
|
} |
|
274
|
|
|
return $this; |
|
275
|
|
|
} |
|
276
|
|
|
/** |
|
277
|
|
|
* @param $label |
|
278
|
|
|
* @param array $attributes |
|
279
|
|
|
* @return $this |
|
280
|
|
|
*/ |
|
281
|
|
|
public function addFile($label,$attributes=[]) |
|
282
|
|
|
{ |
|
283
|
|
|
if($this->Form instanceof form) |
|
284
|
|
|
{ |
|
285
|
|
|
$item = new File($label,$attributes); |
|
286
|
|
|
$this->Form->Attributes()->set('enctype','multipart/form-data'); |
|
287
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
288
|
|
|
$this->Form->append($item); |
|
289
|
|
|
} |
|
290
|
|
|
return $this; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* @param $label |
|
295
|
|
|
* @param array $attributes |
|
296
|
|
|
* @return $this |
|
297
|
|
|
*/ |
|
298
|
|
|
public function addHidden($label,$attributes=[]) |
|
299
|
|
|
{ |
|
300
|
|
|
if($this->Form instanceof form) |
|
301
|
|
|
{ |
|
302
|
|
|
$item = new Hidden($label,$attributes); |
|
303
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
304
|
|
|
$this->Form->append($item); |
|
305
|
|
|
} |
|
306
|
|
|
return $this; |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* @param $html |
|
311
|
|
|
* @return $this |
|
312
|
|
|
*/ |
|
313
|
|
|
public function addHtml($html) |
|
314
|
|
|
{ |
|
315
|
|
|
if($this->Form instanceof form) |
|
316
|
|
|
{ |
|
317
|
|
|
if(gettype($html) === 'string') |
|
318
|
|
|
$this->Form->append($html); |
|
319
|
|
|
} |
|
320
|
|
|
return $this; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* @param $label |
|
325
|
|
|
* @param array $attributes |
|
326
|
|
|
* @return $this |
|
327
|
|
|
*/ |
|
328
|
|
|
public function addImage($label,$attributes=[]) |
|
329
|
|
|
{ |
|
330
|
|
|
if($this->Form instanceof form) |
|
331
|
|
|
{ |
|
332
|
|
|
$item = new Image($label,$attributes); |
|
333
|
|
|
$this->Form->Attributes()->set('enctype','multipart/form-data'); |
|
334
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
335
|
|
|
$this->Form->append($item); |
|
336
|
|
|
} |
|
337
|
|
|
return $this; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* @param $label |
|
342
|
|
|
* @param array $attributes |
|
343
|
|
|
* @return $this |
|
344
|
|
|
*/ |
|
345
|
|
|
public function addMonth($label,$attributes=[]) |
|
346
|
|
|
{ |
|
347
|
|
|
if($this->Form instanceof form) |
|
348
|
|
|
{ |
|
349
|
|
|
$item = new Month($label,$attributes); |
|
350
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
351
|
|
|
$this->Form->append($item); |
|
352
|
|
|
} |
|
353
|
|
|
return $this; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* @param $label |
|
358
|
|
|
* @param array $attributes |
|
359
|
|
|
* @return $this |
|
360
|
|
|
*/ |
|
361
|
|
|
public function addNumber($label,$attributes=[]) |
|
362
|
|
|
{ |
|
363
|
|
|
if($this->Form instanceof form) |
|
364
|
|
|
{ |
|
365
|
|
|
$item = new Number($label,$attributes); |
|
366
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
367
|
|
|
$this->Form->append($item); |
|
368
|
|
|
} |
|
369
|
|
|
return $this; |
|
370
|
|
|
} |
|
371
|
|
|
/** |
|
372
|
|
|
* @param $label |
|
373
|
|
|
* @param array $attributes |
|
374
|
|
|
* @return $this |
|
375
|
|
|
*/ |
|
376
|
|
|
public function addPassword($label,$attributes=[]) |
|
377
|
|
|
{ |
|
378
|
|
|
if($this->Form instanceof form) |
|
379
|
|
|
{ |
|
380
|
|
|
$item = new Password($label,$attributes); |
|
381
|
|
|
$item->Attributes()->set('value', ''); |
|
382
|
|
|
$this->Form->append($item); |
|
383
|
|
|
} |
|
384
|
|
|
return $this; |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* @param $label |
|
389
|
|
|
* @param array $attributes |
|
390
|
|
|
* @return $this |
|
391
|
|
|
*/ |
|
392
|
|
|
public function addPhone($label,$attributes=[]) |
|
393
|
|
|
{ |
|
394
|
|
|
if($this->Form instanceof form) |
|
395
|
|
|
{ |
|
396
|
|
|
$item = new Phone($label,$attributes); |
|
397
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
398
|
|
|
$this->Form->append($item); |
|
399
|
|
|
} |
|
400
|
|
|
return $this; |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
/** |
|
404
|
|
|
* @param $label |
|
405
|
|
|
* @param array $options |
|
406
|
|
|
* @param array $attributes |
|
407
|
|
|
* @return $this |
|
408
|
|
|
*/ |
|
409
|
|
|
public function addRadio($label,$options=[],$attributes=[]) |
|
410
|
|
|
{ |
|
411
|
|
|
if($this->Form instanceof form) |
|
412
|
|
|
{ |
|
413
|
|
|
$item = new Radio($label,$options,$attributes); |
|
414
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
415
|
|
|
$this->Form->append($item); |
|
416
|
|
|
} |
|
417
|
|
|
return $this; |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
/** |
|
421
|
|
|
* @param $label |
|
422
|
|
|
* @param array $attributes |
|
423
|
|
|
* @return $this |
|
424
|
|
|
*/ |
|
425
|
|
|
public function addRange($label,$attributes=[]) |
|
426
|
|
|
{ |
|
427
|
|
|
if($this->Form instanceof form) |
|
428
|
|
|
{ |
|
429
|
|
|
$item = new Range($label,$attributes); |
|
430
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
431
|
|
|
$this->Form->append($item); |
|
432
|
|
|
} |
|
433
|
|
|
return $this; |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
/** |
|
437
|
|
|
* @param $label |
|
438
|
|
|
* @param array $attributes |
|
439
|
|
|
* @return $this |
|
440
|
|
|
*/ |
|
441
|
|
|
public function addReset($label,$attributes=[]) |
|
442
|
|
|
{ |
|
443
|
|
|
if($this->Form instanceof form) |
|
444
|
|
|
{ |
|
445
|
|
|
$item = new Reset($label,$attributes); |
|
446
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
447
|
|
|
$this->Form->append($item); |
|
448
|
|
|
} |
|
449
|
|
|
return $this; |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
/** |
|
453
|
|
|
* @param $label |
|
454
|
|
|
* @param array $attributes |
|
455
|
|
|
* @return $this |
|
456
|
|
|
*/ |
|
457
|
|
|
public function addSearch($label,$attributes=[]) |
|
458
|
|
|
{ |
|
459
|
|
|
if($this->Form instanceof form) |
|
460
|
|
|
{ |
|
461
|
|
|
$item = new Search($label,$attributes); |
|
462
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
463
|
|
|
$this->Form->append($item); |
|
464
|
|
|
} |
|
465
|
|
|
return $this; |
|
466
|
|
|
} |
|
467
|
|
|
/** |
|
468
|
|
|
* @param $label |
|
469
|
|
|
* @param array $options |
|
470
|
|
|
* @param array $attributes |
|
471
|
|
|
* @return $this |
|
472
|
|
|
*/ |
|
473
|
|
|
public function addSelect($label,array $options = [],$attributes=[]) |
|
474
|
|
|
{ |
|
475
|
|
|
if($this->Form instanceof form) |
|
476
|
|
|
{ |
|
477
|
|
|
$item = new Select($label,$options,$attributes); |
|
478
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
479
|
|
|
$this->Form->append($item); |
|
480
|
|
|
} |
|
481
|
|
|
return $this; |
|
482
|
|
|
} |
|
483
|
|
|
/** |
|
484
|
|
|
* @param $label |
|
485
|
|
|
* @param array $attributes |
|
486
|
|
|
* @return $this |
|
487
|
|
|
*/ |
|
488
|
|
|
public function addSubmit($label,$attributes=[]) |
|
489
|
|
|
{ |
|
490
|
|
|
if($this->Form instanceof form) |
|
491
|
|
|
{ |
|
492
|
|
|
$item = new Submit($label,$attributes); |
|
493
|
|
|
$this->Form->append($item); |
|
494
|
|
|
} |
|
495
|
|
|
return $this; |
|
496
|
|
|
} |
|
497
|
|
|
|
|
498
|
|
|
/** |
|
499
|
|
|
* @param $label |
|
500
|
|
|
* @param array $attributes |
|
501
|
|
|
* @return $this |
|
502
|
|
|
*/ |
|
503
|
|
|
public function addText($label,$attributes=[]) |
|
504
|
|
|
{ |
|
505
|
|
|
if($this->Form instanceof form) |
|
506
|
|
|
{ |
|
507
|
|
|
$item = new Text($label,$attributes); |
|
508
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
509
|
|
|
$this->Form->append($item); |
|
510
|
|
|
} |
|
511
|
|
|
return $this; |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
/** |
|
515
|
|
|
* @param $label |
|
516
|
|
|
* @param array $attributes |
|
517
|
|
|
* @return $this |
|
518
|
|
|
*/ |
|
519
|
|
|
public function addTextarea($label,$attributes=[]) |
|
520
|
|
|
{ |
|
521
|
|
|
if($this->Form instanceof form) |
|
522
|
|
|
{ |
|
523
|
|
|
$item = new Textarea($label,$attributes); |
|
524
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
525
|
|
|
$this->Form->append($item); |
|
526
|
|
|
} |
|
527
|
|
|
return $this; |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
|
|
/** |
|
531
|
|
|
* @param $label |
|
532
|
|
|
* @param array $attributes |
|
533
|
|
|
* @return $this |
|
534
|
|
|
*/ |
|
535
|
|
|
public function addTime($label,$attributes=[]) |
|
536
|
|
|
{ |
|
537
|
|
|
if($this->Form instanceof form) |
|
538
|
|
|
{ |
|
539
|
|
|
$item = new Time($label,$attributes); |
|
540
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
541
|
|
|
$this->Form->append($item); |
|
542
|
|
|
} |
|
543
|
|
|
return $this; |
|
544
|
|
|
} |
|
545
|
|
|
|
|
546
|
|
|
/** |
|
547
|
|
|
* @param $label |
|
548
|
|
|
* @param array $attributes |
|
549
|
|
|
* @return $this |
|
550
|
|
|
*/ |
|
551
|
|
|
public function addUrl($label,$attributes=[]) |
|
552
|
|
|
{ |
|
553
|
|
|
if($this->Form instanceof form) |
|
554
|
|
|
{ |
|
555
|
|
|
$item = new Url($label,$attributes); |
|
556
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
557
|
|
|
$this->Form->append($item); |
|
558
|
|
|
} |
|
559
|
|
|
return $this; |
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
/** |
|
563
|
|
|
* @param $label |
|
564
|
|
|
* @param array $attributes |
|
565
|
|
|
* @return $this |
|
566
|
|
|
*/ |
|
567
|
|
|
public function addVideo($label,$attributes=[]) |
|
568
|
|
|
{ |
|
569
|
|
|
if($this->Form instanceof form) |
|
570
|
|
|
{ |
|
571
|
|
|
$item = new Video($label,$attributes); |
|
572
|
|
|
$this->Form->Attributes()->set('enctype','multipart/form-data'); |
|
573
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
574
|
|
|
$this->Form->append($item); |
|
575
|
|
|
} |
|
576
|
|
|
return $this; |
|
577
|
|
|
} |
|
578
|
|
|
/** |
|
579
|
|
|
* @param $label |
|
580
|
|
|
* @param array $attributes |
|
581
|
|
|
* @return $this |
|
582
|
|
|
*/ |
|
583
|
|
|
public function addWeek($label,$attributes=[]) |
|
584
|
|
|
{ |
|
585
|
|
|
if($this->Form instanceof form) |
|
586
|
|
|
{ |
|
587
|
|
|
$item = new Week($label,$attributes); |
|
588
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
589
|
|
|
$this->Form->append($item); |
|
590
|
|
|
} |
|
591
|
|
|
return $this; |
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
/** |
|
595
|
|
|
* @param $label |
|
596
|
|
|
* @param array $attributes |
|
597
|
|
|
* @return $this |
|
598
|
|
|
*/ |
|
599
|
|
|
public function addYesNo($label,$attributes=[]) |
|
600
|
|
|
{ |
|
601
|
|
|
if($this->Form instanceof form) |
|
602
|
|
|
{ |
|
603
|
|
|
$item = new YesNo($label,$attributes); |
|
604
|
|
|
$item->Attributes()->set('value', $this->getDefaultValue($item)); |
|
605
|
|
|
$this->Form->append($item); |
|
606
|
|
|
} |
|
607
|
|
|
return $this; |
|
608
|
|
|
} |
|
609
|
|
|
/** |
|
610
|
|
|
* @param bool $print |
|
611
|
|
|
* @return null|string |
|
612
|
|
|
*/ |
|
613
|
|
|
public function Close($print=true) |
|
614
|
|
|
{ |
|
615
|
|
|
$html = null; |
|
616
|
|
|
if ($this->Form instanceof form) |
|
617
|
|
|
{ |
|
618
|
|
|
if($this->Fieldset instanceof fieldsetGenerator) |
|
619
|
|
|
$this->Form->append($this->Fieldset->Close()); |
|
620
|
|
|
$html = $this->Form->RenderHtml(); |
|
621
|
|
|
$this->Form = null; |
|
622
|
|
|
if($print) |
|
623
|
|
|
print_r($html); |
|
624
|
|
|
} |
|
625
|
|
|
return $html; |
|
626
|
|
|
} |
|
627
|
|
|
/** |
|
628
|
|
|
* @return mixed |
|
629
|
|
|
*/ |
|
630
|
|
|
public function Errors() |
|
631
|
|
|
{ |
|
632
|
|
|
return $this->Errors; |
|
633
|
|
|
} |
|
634
|
|
|
/** |
|
635
|
|
|
* @param $element |
|
636
|
|
|
* @param $default |
|
637
|
|
|
* @return mixed |
|
638
|
|
|
*/ |
|
639
|
|
|
private function getDefaultValue(FormElement $element,$default=null) |
|
640
|
|
|
{ |
|
641
|
|
|
$name = $element->Attributes()->get('name'); |
|
642
|
|
|
$method = strtoupper($this->Request->getMethod()); |
|
643
|
|
|
switch($method){ |
|
644
|
|
|
case 'POST': |
|
645
|
|
|
case 'PUT': |
|
646
|
|
|
case 'DELETE': |
|
647
|
|
|
case 'PATCH': |
|
648
|
|
|
$Request = $this->Request->request; |
|
649
|
|
|
break; |
|
650
|
|
|
default: |
|
651
|
|
|
$Request = $this->Request->query; |
|
652
|
|
|
break; |
|
653
|
|
|
} |
|
654
|
|
|
if(!$value = $Request->get($name, $default)) |
|
655
|
|
|
$value = $element->Attributes()->get('value', $default); |
|
656
|
|
|
return $value; |
|
657
|
|
|
} |
|
658
|
|
|
/** |
|
659
|
|
|
* @param array $attributes |
|
660
|
|
|
* @return $this |
|
661
|
|
|
*/ |
|
662
|
|
|
public function Open($attributes = []) |
|
663
|
|
|
{ |
|
664
|
|
|
if($this->Form instanceof form) |
|
665
|
|
|
$this->Close(); |
|
666
|
|
|
$this->Form = new form($attributes); |
|
667
|
|
|
return $this; |
|
668
|
|
|
} |
|
669
|
|
|
} |
|
670
|
|
|
|
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