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