ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
with_contraints.php
Go to the documentation of this file.
1<?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 $validation = new \ILIAS\Validation\Factory($data, $lng);
15 $pw_validation = $validation->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 ->withAdditionalConstraint(
21 $validation->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 //the above can be shortcut into:
30 $pwd_input2 = $ui->input()->field()->password("Password", "constraints in place.")
31 ->withStandardConstraints(8, true, true, true, true);
32
33 //Step 2: Define the form and attach the field.
34 $DIC->ctrl()->setParameterByClass(
35 'ilsystemstyledocumentationgui',
36 'example',
37 'password'
38 );
39 $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
40 $form = $ui->input()->container()->form()->standard($form_action, ['pwd' => $pwd_input, 'pwd2' => $pwd_input2]);
41
42 //Step 3: Define some data processing.
43 $result = '';
44 if ($request->getMethod() == "POST"
45 && $request->getQueryParams()['example'] == 'password') {
46 $form = $form->withRequest($request);
47 $result = $form->getData();
48 }
49
50 //Step 4: Render the form.
51 return
52 $renderer->render($form);
53}
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$lng
$data
Definition: bench.php:6
with_contraints()
Passwords (when setting) usually have some constraints.