ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
with_contraints.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
48 function with_contraints()
49 {
50  //Step 0: Declare dependencies
51  global $DIC;
52  $ui = $DIC->ui()->factory();
53  $lng = $DIC->language();
54  $renderer = $DIC->ui()->renderer();
55  $request = $DIC->http()->request();
56  $data = new \ILIAS\Data\Factory();
57  $refinery = new \ILIAS\Refinery\Factory($data, $lng);
58  $pw_validation = $refinery->password();
59 
60  //Step 1: Define the input field
61  //and add some constraints.
62  $pwd_input = $ui->input()->field()->password("Password", "constraints in place.")
63  ->withAdditionalTransformation(
64  $refinery->logical()->parallel([
65  $pw_validation->hasMinLength(8),
66  $pw_validation->hasLowerChars(),
67  $pw_validation->hasUpperChars(),
68  $pw_validation->hasNumbers(),
69  $pw_validation->hasSpecialChars()
70  ])
71  );
72 
73  //Step 2: Define the form and attach the field.
74  $form = $ui->input()->container()->form()->standard('#', ['pwd' => $pwd_input]);
75 
76  //Step 3: Define some data processing.
77  $result = '';
78  if ($request->getMethod() == "POST") {
79  $form = $form->withRequest($request);
80  $result = $form->getData();
81  }
82 
83  //Step 4: Render the form/result.
84  return
85  "<pre>" . print_r($result, true) . "</pre><br/>" .
86  $renderer->render($form);
87 }
with_contraints()
description: > Passwords (when setting) usually have some constraints.
$renderer
global $DIC
Definition: shib_login.php:22
global $lng
Definition: privfeed.php:31