ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
with_contraints.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
32 function with_contraints()
33 {
34  //Step 0: Declare dependencies
35  global $DIC;
36  $ui = $DIC->ui()->factory();
37  $lng = $DIC->language();
38  $renderer = $DIC->ui()->renderer();
39  $request = $DIC->http()->request();
40  $data = new \ILIAS\Data\Factory();
41  $refinery = new \ILIAS\Refinery\Factory($data, $lng);
42  $pw_validation = $refinery->password();
43 
44  //Step 1: Define the input field
45  //and add some constraints.
46  $pwd_input = $ui->input()->field()->password("Password", "constraints in place.")
47  ->withAdditionalTransformation(
48  $refinery->logical()->parallel([
49  $pw_validation->hasMinLength(8),
50  $pw_validation->hasLowerChars(),
51  $pw_validation->hasUpperChars(),
52  $pw_validation->hasNumbers(),
53  $pw_validation->hasSpecialChars()
54  ])
55  );
56 
57  //Step 2: Define the form and attach the field.
58  $form = $ui->input()->container()->form()->standard('#', ['pwd' => $pwd_input]);
59 
60  //Step 3: Define some data processing.
61  $result = '';
62  if ($request->getMethod() == "POST") {
63  $form = $form->withRequest($request);
64  $result = $form->getData();
65  }
66 
67  //Step 4: Render the form/result.
68  return
69  "<pre>" . print_r($result, true) . "</pre><br/>" .
70  $renderer->render($form);
71 }
with_contraints()
description: > Passwords (when setting) usually have some constraints.
$renderer
global $DIC
Definition: shib_login.php:25
global $lng
Definition: privfeed.php:32