Skip to content

Commit e837631

Browse files
committed
Update readme to v.2.0.0
1 parent 62b53f2 commit e837631

File tree

1 file changed

+65
-39
lines changed

1 file changed

+65
-39
lines changed

README.md

Lines changed: 65 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,38 @@ If you prefer you can create a composer.json in your project folder.
1515
```json
1616
{
1717
"require": {
18-
"fullstackpe/micro-form": "^1.0"
18+
"fullstackpe/micro-form": "^2.0"
1919
}
2020
}
2121
```
2222

2323
#### How it works?
2424

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+
2535
Create an instance of the class micro\form\Builder
2636

2737
```php
2838
<?php
2939

30-
$json = '[
31-
"name",
32-
"lastname"
33-
]';
40+
$json = '{
41+
"inputs": [
42+
{
43+
"name": "name"
44+
},
45+
{
46+
"name": "lastname"
47+
}
48+
]
49+
}';
3450

3551
$builder = new \micro\form\Builder();
3652
$form = $builder->render($json);
@@ -56,15 +72,17 @@ It is possible to use more complex Json objects for example
5672
```php
5773
<?php
5874

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+
}';
6886

6987
$builder = new \micro\form\Builder();
7088
$form = $builder->render($json);
@@ -85,13 +103,15 @@ Repeaters are supported out of the box for example
85103
```php
86104
<?php
87105

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+
}';
95115

96116
$builder = new \micro\form\Builder();
97117
$form = $builder->render($json);
@@ -123,20 +143,20 @@ You can create block with inputs to repeat for example
123143
<?php
124144

125145
// 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+
}';
140160

141161
$builder = new \micro\form\Builder();
142162
$form = $builder->render($json);
@@ -170,10 +190,16 @@ Micro-form supports default values too. Just send a key value array as the secon
170190
```php
171191
<?php
172192

173-
$json = '[
174-
"name",
175-
"lastname"
176-
]';
193+
$json = '{
194+
"inputs": [
195+
{
196+
"name": "name"
197+
},
198+
{
199+
"name": "lastname"
200+
}
201+
]
202+
}]';
177203

178204
$builder = new \micro\form\Builder();
179205
$form = $builder->render($json, ['name' => 'marco', 'lastname' => 'milon']);

0 commit comments

Comments
 (0)