ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
with_required.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
16 function with_required()
17 {
18  //Step 0: Declare dependencies
19  global $DIC;
20  $ui = $DIC->ui()->factory();
21  $renderer = $DIC->ui()->renderer();
22  $request = $DIC->http()->request();
23 
24  // Step 1: define the text field and make it a required field,
25  // i.e. checking for its default requirement constraint
26  // (for text fields: value must have a minimum length of 1)
27  $text_input = $ui->input()->field()->text("Enter a name", "And make it a good one!");
28  $text_input = $text_input->withRequired(true);
29 
30  //Step 2: define form and form actions
31  $form = $ui->input()->container()->form()->standard('#', [ $text_input]);
32 
33  //Step 3: implement some form data processing.
34  if ($request->getMethod() == "POST") {
35  $form = $form->withRequest($request);
36  $result = $form->getData();
37  } else {
38  $result = "No result yet.";
39  }
40 
41  //Step 4: Render the checkbox with the enclosing form.
42  return
43  "<pre>" . print_r($result, true) . "</pre><br/>" .
44  $renderer->render($form);
45 }
$renderer
global $DIC
Definition: shib_login.php:25
with_required()
description: > Example showing the use of the withRequired() method