-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
127 lines (118 loc) · 3.75 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<head>
<script src="vendor/jquery/jquery/jquery-1.12.1.min.js"></script>
<script src="src/assets/default.js"></script>
</head>
<?php
/**
* User: Ionov George
* Date: 12.02.2016
* Time: 18:29
*/
require 'vendor/autoload.php';
use \NewInventor\Form\Form;
use \NewInventor\Form\Field\Input;
use \NewInventor\Form\Block;
function asd(\NewInventor\Form\Interfaces\FormInterface $form)
{
return true;
}
class A
{
public function asd(\NewInventor\Form\Interfaces\FormInterface $form)
{
$form->load($form->getDataArray());
return true;
}
public static function zxc(\NewInventor\Form\Interfaces\FormInterface $form)
{
return true;
}
}
session_start();
$a = new A();
$form = new Form('form1', null, Form::METHOD_POST, 'title1', Form::ENC_TYPE_MULTIPART);
$form
->radioSet('name1', 1)
->addOptionArray(['0' => 'value0', '1' => 'value1', '2' => 'value2'])
->end()
->checkBoxSet('che')
->addOptionArray(['value1' => 'title1', 'value2' => 'title2', 'value3' => 'title3'])
->end()
->checkbox('cccc', false)
->title('Lfff')
->attribute('value', 'Yes')
->end()
->checkbox('cccc3', false)
->attribute('value', 'Yes1')
->end()
->checkbox('cccc4', false)
->attribute('value', 'Yes2')
->end()
->password('qwee', '123')
->title('titleeee')
->attribute('class', 'special')
->attribute('id', 'qwe1')
->validator('string', ['minLength' => 4])
->end()
->repeatable(new Input('testRepeat', '', 'repeat title'))
->block('test')
->text('qwe', 'qwe')
->title('QWE')
->attribute('class', 'show')
->validator('string', ['minLength' => 6, 'maxLength' => 12])
->validator(
function ($objectName, $value) {
if(substr($value, 0, 2) == 'as'){
return true;
}
throw new \NewInventor\Form\Validator\Exceptions\String\Base($objectName, 'Значение поля "{n}" должно начинаться с "as"');
}
)
->end()
->end()
->block('innerBlock')
->text('city')
->title('Город')
->validator('required')
->validator('integer', ['min' => 5, 'max' => 10])
->attribute('data-city-input')
->end()
->select('selectBox1', ['1', '2', '3'])
->multiple()
->addOptionArray(['1' => 'qwerty', '2' => 'asdfgh', '3' => 'zxcvbn', '4' => 'qazwsx'])
->attribute('size', 5)
->end()
->block('second')
->textArea('message', 'input the message here...')
->rows(5)
->cols(50)
->end()
->end()
->end()
->repeatable(
(new Block('fullName', 'Полное имя участника.'))
->attribute('data-repeatable')
->text('family')->title('Фамилия')->end()
->text('name')->title('Имя')->end()
->text('surname')->title('Отчество')->end()
)
// you can do so
// ->handler(new Handler\AbstractHandler($form, 'save', 'Сохранить', function(\NewInventor\Form\Interfaces\FormInterface $form){
// return true;
// }))
->handler('asd', 'save', 'Сохранить')
->handler(function (\NewInventor\Form\Interfaces\FormInterface $form) {
$form->load([]);
return true;
}, 'reset111', 'Сбросить111')
// you can do so
// ->handler(new Handler\ResetHandler($form), 'resettttt', 'Reseeeettttt')
// ->handler(new Handler\ResetHandler($form))
->handler([$a, 'asd'], 'tot', 'Еще')
->handler(['A', 'zxc'], 'tot1', 'Еще1')
->successMessage('Данные сохранены.')
->end();
if ($form->load() && $form->validate()) {
$form->save();
}
echo $form->getString();