ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
with_required_input.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
20 {
21  global $DIC;
22  $ui = $DIC->ui()->factory();
23  $renderer = $DIC->ui()->renderer();
24  $request = $DIC->http()->request();
25 
26  $text_input = $ui->input()->field()
27  ->text("Required Input", "User needs to fill this field")
28  ->withRequired(true);
29 
30  $section = $ui->input()->field()->section(
31  [$text_input],
32  "Section with required field",
33  "The Form should show an explaining hint at the bottom"
34  );
35 
36  $DIC->ctrl()->setParameterByClass(
37  'ilsystemstyledocumentationgui',
38  'example_name',
39  'required'
40  );
41  $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
42 
43  $form = $ui->input()->container()->form()->standard($form_action, [$section]);
44 
45  if ($request->getMethod() == "POST"
46  && array_key_exists('example_name', $request->getQueryParams())
47  && $request->getQueryParams()['example_name'] == 'required') {
48  $form = $form->withRequest($request);
49  $result = $form->getData();
50  } else {
51  $result = "No result yet.";
52  }
53 
54  return
55  "<pre>" . print_r($result, true) . "</pre><br/>" .
56  $renderer->render($form);
57 }
$renderer
with_required_input()
description: > Example showing a Form with required fields.
global $DIC
Definition: shib_login.php:25