Skip to content

Commit d5c442c

Browse files
committed
update
1 parent 282ccce commit d5c442c

File tree

4 files changed

+105
-12
lines changed

4 files changed

+105
-12
lines changed

docs/index.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,32 @@ In the future we will add support for other frameworks, such as bootstrap 5.
104104

105105
## Backend frameworks
106106

107+
This package has been tested with the MintyPHP backend framework. It can also be used with other frameworks as this package has no dependencies at all.
107108

109+
Although we don't recommend you to use MintyPHP Forms without a framework, it is certainly possible, see the full example.
108110

109111
## Full example
110112

111-
Although we don't encourage you to use MintyPHP Forms without a framework, it is certainly possible:
113+
The Form object has the following data methods:
114+
115+
- **fill**: Fill the form with an array of data (e.g. $_POST)
116+
- **validate**: Validate the form and add errors where needed
117+
- **addErrors**: Add custom errors (after validation)
118+
- **extract**: Extract the filled in form values
119+
- **render**: Output the form with or without root element
120+
121+
These data methods are typically used on GET:
122+
123+
- GET:
124+
- fill (with default values or from database)
125+
- render
126+
- POST:
127+
- fill (from POST data)
128+
- validate
129+
- on success: extract
130+
- on errors: render
131+
132+
You can see how these are used in the following full example:
112133

113134
```php
114135
<?php

docs/methods.md

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,95 @@
11
# Methods
22

3+
This pages contains an overview of the structural methods that you can use to build a form.
4+
5+
All structural methods return a self-reference allowing to chain the method calls.
6+
37
## Form
48

5-
The Form object has the following data methods:
9+
Is created by:
610

7-
- **fill**: Fill the form with an array of data (e.g. $_POST)
8-
- **extract**: Extract the filled in form values
9-
- **validate**: Validate the form and add errors where needed
10-
- **addErrors**: Add custom errors (after validation)
11-
- **render**: Output the form with or without root element
11+
- **form**: Create a Form
1212

13-
And the following structure building methods:
13+
And has the following structure building methods:
1414

1515
- **fieldsets**: Add multiple Fieldset elements
1616
- **fieldset**: Add a single Fieldset element
1717
- **fields**: Add multiple Field elements
1818
- **field**: Add a single Field element
19+
- **header**: Add a single Header element
20+
21+
Instead of:
22+
23+
$form = E::form()->fields([...]);
24+
25+
You can use:
26+
27+
$form = E::form([...]);
28+
29+
as a shortcut.
30+
31+
## Fieldset (optional)
32+
33+
Is created by:
34+
35+
- **fieldset**: Create a Fieldset
36+
37+
And has the following structure building methods:
38+
39+
- **legend**: Add a Legend element to the Fieldset
40+
- **header**: Add a single Header element
41+
- **fields**: Add multiple Field elements
42+
- **field**: Add a single Field element
43+
44+
NB: Unless required you should use "fields", "field" and "header" on Form instead.
45+
46+
## Field
47+
48+
Is created by:
49+
50+
- **field**: Create a Field
51+
52+
And has the following structure building methods:
53+
54+
- **label**: Set the label for the Field
55+
- **control**: Set the control for the Field
56+
- **validators**: Set the validators for the Field
57+
58+
Instead of:
59+
60+
$form = E::field()->control($control)->label($label)->validators([$validator]);
61+
62+
You can use:
63+
64+
$form = E::field($control,$label,[$validator]);
65+
66+
as a shortcut.
67+
68+
## Input
69+
70+
Is created by:
71+
72+
- **text**: Create a text Input
73+
- **password**: Create a password Input
74+
- **email**: Create an email Input
75+
- **number**: Create a number Input
76+
- **submit**: Create a submit Input
77+
78+
And has the following structure building methods:
79+
80+
- **type**: Set the type of the Input
81+
- **name**: Set the name of the Input
82+
- **value**: Set the value of the Input
83+
- **placeholder**: Set the placeholder of the Input
84+
85+
Instead of:
86+
87+
$form = E::text()->name($name)->placeholder($placeholder);
88+
$form = E::submit()->value($value);
1989

20-
## Fieldset
90+
You can use:
2191

92+
$form = E::text($name,$placeholder);
93+
$form = E::submit($value);
2294

95+
as a shortcut.

src/Elements.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public static function field(?Control $control = null, ?Label $label = null, arr
4545
return $field;
4646
}
4747

48-
49-
public static function create(string $className): object
48+
protected static function create(string $className): object
5049
{
5150
$class = self::$namespaces[self::$style] . $className;
5251
if (class_exists($class)) {

src/Field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function setError(string $message): void
137137
if ($message) {
138138
if (!$this->error) {
139139
/** @var Error */
140-
$error = Elements::create('Error');
140+
$error = Elements::error();
141141
$this->error = $error;
142142
}
143143
} else if ($this->hideError) {

0 commit comments

Comments
 (0)