ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
with_contraints.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 function with_contraints()
11 {
12  //Step 0: Declare dependencies
13  global $DIC;
14  $ui = $DIC->ui()->factory();
15  $lng = $DIC->language();
16  $renderer = $DIC->ui()->renderer();
17  $request = $DIC->http()->request();
18  $data = new \ILIAS\Data\Factory();
19  $refinery = new \ILIAS\Refinery\Factory($data, $lng);
20  $pw_validation = $refinery->password();
21 
22  //Step 1: Define the input field
23  //and add some constraints.
24  $pwd_input = $ui->input()->field()->password("Password", "constraints in place.")
25  ->withAdditionalTransformation(
26  $refinery->logical()->parallel([
27  $pw_validation->hasMinLength(8),
28  $pw_validation->hasLowerChars(),
29  $pw_validation->hasUpperChars(),
30  $pw_validation->hasNumbers(),
31  $pw_validation->hasSpecialChars()
32  ])
33  );
34 
35  //Step 2: Define the form and attach the field.
36  $form = $ui->input()->container()->form()->standard('#', ['pwd' => $pwd_input]);
37 
38  //Step 3: Define some data processing.
39  $result = '';
40  if ($request->getMethod() == "POST") {
41  $form = $form->withRequest($request);
42  $result = $form->getData();
43  }
44 
45  //Step 4: Render the form/result.
46  return
47  "<pre>" . print_r($result, true) . "</pre><br/>" .
48  $renderer->render($form);
49 }
with_contraints()
Passwords (when setting) usually have some constraints.
password(string $pass)
Definition: Factory.php:98
$lng
global $DIC
Definition: feed.php:28
Refinery Factory $refinery