ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
with_required.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
32 function with_required()
33 {
34  //Step 0: Declare dependencies
35  global $DIC;
36  $ui = $DIC->ui()->factory();
37  $renderer = $DIC->ui()->renderer();
38  $request = $DIC->http()->request();
39 
40  // Step 1: define the text field and make it a required field,
41  // i.e. checking for its default requirement constraint
42  // (for text fields: value must have a minimum length of 1)
43  $text_input = $ui->input()->field()->text("Enter a name", "And make it a good one!");
44  $text_input = $text_input->withRequired(true);
45 
46  //Step 2: define form and form actions
47  $form = $ui->input()->container()->form()->standard('#', [ $text_input]);
48 
49  //Step 3: implement some form data processing.
50  if ($request->getMethod() == "POST") {
51  $form = $form->withRequest($request);
52  $result = $form->getData();
53  } else {
54  $result = "No result yet.";
55  }
56 
57  //Step 4: Render the checkbox with the enclosing form.
58  return
59  "<pre>" . print_r($result, true) . "</pre><br/>" .
60  $renderer->render($form);
61 }
$renderer
global $DIC
Definition: shib_login.php:22
with_required()
description: > Example showing the use of the withRequired() method