ILIAS  release_7 Revision v7.30-3-g800a261c036
with_contraints.php File Reference

Go to the source code of this file.

Functions

 with_contraints ()
 Passwords (when setting) usually have some constraints. More...
 

Function Documentation

◆ with_contraints()

with_contraints ( )

Passwords (when setting) usually have some constraints.

Definition at line 5 of file with_contraints.php.

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}
$result
global $DIC
Definition: goto.php:24
$lng
$data
Definition: storeScorm.php:23

References $data, $DIC, $lng, and $result.