@@ -142,65 +142,7 @@ These data methods are typically used on GET:
142142
143143You can see how these are used in the following full example:
144144
145- ``` php
146- <?php
147-
148- // alias the most used classes
149- use MintyPHP\Form\Elements as E;
150- use MintyPHP\Form\Validator\Validators as V;
151-
152- // ensure all classes are (auto)loaded:
153- require_once 'vendor/autoload.php';
154-
155- // set style to Bulma
156- E::$style = 'bulma';
157-
158- // create a form object
159- $form = E::form([
160- E::field(E::text('username'), E::label('Username'), [V::required('Username is required')]),
161- E::field(E::password('password'), E::label('Password')),
162- E::field(E::submit('Login')),
163- ]);
164-
165- // check if the form has been submitted
166- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
167- // fill the form with the submitted data
168- $form->fill($_POST);
169- // if the form is valid, process the data
170- if ($form->validate()) {
171- // extract the data
172- $data = $form->extract();
173- // process the data (e.g., login, save to database, etc.)
174- if ($data['username'] == 'user' && $data['password'] == 'pass') {
175- // redirect to the dashboard page
176- die('logged in, redirecting to dashboard...');
177- } else {
178- // invalidate credentials
179- $form->addErrors([
180- 'username' => 'Invalid username/password combination',
181- 'password' => 'Invalid username/password combination',
182- ]);
183- }
184- }
185- } else {
186- // if the form is not submitted, fill it with empty values
187- $form->fill(['username' => '', 'password' => '']);
188- }
189- ?>
190- <!DOCTYPE html>
191- <html lang =" en" >
192-
193- <head >
194- <link rel =" stylesheet" href =" https://cdnjs.cloudflare.com/ajax/libs/bulma/1.0.3/css/bulma.min.css" >
195- </head >
196-
197- <body class =" container p-5" >
198- <h1 class =" title" >Login</h1 >
199- <?php $form->render(); ?>
200- </body >
201-
202- </html >
203- ```
145+ - [ example.php] ( example.php )
204146
205147Renders as:
206148
0 commit comments