You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-39Lines changed: 65 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,22 +15,38 @@ If you prefer you can create a composer.json in your project folder.
15
15
```json
16
16
{
17
17
"require": {
18
-
"fullstackpe/micro-form": "^1.0"
18
+
"fullstackpe/micro-form": "^2.0"
19
19
}
20
20
}
21
21
```
22
22
23
23
#### How it works?
24
24
25
+
Micro-form reads a json file to render an Html form. The json file is just an object with three properties: name, inputs, repeat.
26
+
27
+
*_name_ is the name of the array of inputs.
28
+
*_inputs_ is an array objects that represents the inputs.
29
+
*_repeat_ is a boolean value to set the array of inputs repeatable.
30
+
31
+
The json used to render the form has to validated against this [Json-schema](https://github.com/marcomilon/micro-form/blob/master/src/form/schemas/input.json).
32
+
33
+
**Examples**
34
+
25
35
Create an instance of the class micro\form\Builder
26
36
27
37
```php
28
38
<?php
29
39
30
-
$json = '[
31
-
"name",
32
-
"lastname"
33
-
]';
40
+
$json = '{
41
+
"inputs": [
42
+
{
43
+
"name": "name"
44
+
},
45
+
{
46
+
"name": "lastname"
47
+
}
48
+
]
49
+
}';
34
50
35
51
$builder = new \micro\form\Builder();
36
52
$form = $builder->render($json);
@@ -56,15 +72,17 @@ It is possible to use more complex Json objects for example
56
72
```php
57
73
<?php
58
74
59
-
$json = '[
60
-
{
61
-
"input": "text",
62
-
"name": "username",
63
-
"id": "username",
64
-
"placeholder": "Username",
65
-
"label": "Enter username"
66
-
}
67
-
]';
75
+
$json = '{
76
+
"inputs": [
77
+
{
78
+
"input": "text",
79
+
"name": "username",
80
+
"id": "username",
81
+
"placeholder": "Username",
82
+
"label": "Enter username"
83
+
}
84
+
]
85
+
}';
68
86
69
87
$builder = new \micro\form\Builder();
70
88
$form = $builder->render($json);
@@ -85,13 +103,15 @@ Repeaters are supported out of the box for example
85
103
```php
86
104
<?php
87
105
88
-
$json = '[
89
-
{
90
-
"input": "text",
91
-
"name": "username",
92
-
"repeat": true
93
-
}
94
-
]';
106
+
$json = '{
107
+
"inputs": [
108
+
{
109
+
"input": "text",
110
+
"name": "username",
111
+
"repeat": true
112
+
}
113
+
]
114
+
}';
95
115
96
116
$builder = new \micro\form\Builder();
97
117
$form = $builder->render($json);
@@ -123,20 +143,20 @@ You can create block with inputs to repeat for example
123
143
<?php
124
144
125
145
// Json represent a block with id "users" and with two imputs: username and password.
126
-
$json = '[
127
-
{
128
-
"users": [
129
-
{
130
-
"input": "text",
131
-
"name": "username"
132
-
},
133
-
{
134
-
"input": "text",
135
-
"name": "password"
136
-
}
137
-
]
138
-
}
139
-
]';
146
+
$json = '{
147
+
"name": "users",
148
+
"repeat": true,
149
+
"inputs": [
150
+
{
151
+
"input": "text",
152
+
"name": "username"
153
+
},
154
+
{
155
+
"input": "text",
156
+
"name": "password"
157
+
}
158
+
]
159
+
}';
140
160
141
161
$builder = new \micro\form\Builder();
142
162
$form = $builder->render($json);
@@ -170,10 +190,16 @@ Micro-form supports default values too. Just send a key value array as the secon
0 commit comments