ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
with_contraints.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
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}
$renderer
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26