forked from oscarotero/form-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.php
74 lines (66 loc) · 1.98 KB
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
require __DIR__.'/src/autoloader.php';
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', __DIR__.'/php.log');
use FormManager\Builder as F;
use FormManager\InvalidValueException;
$form = F::Form([
'data' => F::group([
'dia' => F::number()->label('Dia'),
'mes' => F::number()->label('Mes'),
]),
'colores' => F::choose([
'red' => F::radio()->label('Red'),
'blue' => F::radio()->label('Blue'),
'green' => F::radio()->label('Green'),
]),
'personas' => F::collection([
'nome' => F::text()->label('Nome'),
'apelido' => F::text()->label('Apelidos'),
]),
'bloques' => F::collectionMultiple([
'texto' => [
'titulo' => F::text()->label('Titulo'),
'texto' => F::textarea()->label('Texto'),
],
'cita' => [
'texto' => F::textarea()->label('Texto'),
'autor' => F::text()->label('Autor'),
],
]),
'enviar' => F::submit()->html('Enviar'),
]);
$form->fieldsets([
'personal' => [
'nome' => F::text()
->label('O teu nome')
->addValidator(function ($input) {
if ($input->val() !== 'Lolo') {
throw new InvalidValueException("Nome non valido, debe ser Lolo");
}
})
->datalist([
'Lolo' => 'Lolo',
'Manolo' => 'Manolo',
]),
'apelido' => F::text()->label('O teu apelido'),
'idade' => F::select()
->options([
1 => 'Menor de idade',
2 => 'Maiore de idade',
])
->label('Idade')
->render(function ($input) {
return '<p>'.$input.'</p>';
}),
],
]);
$form['nome']->errorLabel->class('my-error');
$form->loadFromGlobals();
if (!$form->isValid()) {
echo 'Invalid values';
}
echo $form;