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