ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
with_usage_in_legacy_form.php
Go to the documentation of this file.
1 <?php
2 
3 function with_usage_in_legacy_form()
4 {
5  // Build our form
6  $form = new ilPropertyFormGUI();
7  $form->setId('myUniqueFormId');
8  $form->setTitle('Form');
9  $form->setFormAction($_SERVER['REQUEST_URI'] . '&example=6');
10  $form->setPreventDoubleSubmission(false);
11  $flag = new ilHiddenInputGUI('submitted');
12  $flag->setValue('1');
13  $form->addItem($flag);
14  $item = new ilTextInputGUI('Title', 'title');
15  $item->setRequired(true);
16  $form->addItem($item);
17  $item = new ilTextareaInputGUI('Description', 'description');
18  $item->setRequired(true);
19  $form->addItem($item);
20  $item = new ilFileStandardDropzoneInputGUI('cancel', 'Files', 'files');
21  $item->setUploadUrl($form->getFormAction());
22  $item->setSuffixes([ 'jpg', 'gif', 'png', 'pdf' ]);
23  $item->setInfo('Allowed file types: ' . implode(', ', $item->getSuffixes()));
24  $item->setDropzoneMessage('For the purpose of this demo, any PDF file will fail to upload');
25  $form->addItem($item);
26  $form->addCommandButton('save', 'Save');
27 
28  // Check for submission
29  global $DIC;
30  if (isset($_POST['submitted']) && $_POST['submitted']) {
31  if ($form->checkInput()) {
32  // We might also want to process and save other form data here
33  $upload = $DIC->upload();
34  // Check if this is a request to upload a file
35  if ($upload->hasUploads()) {
36  try {
37  $upload->process();
38  // We simulate a failing response for any uploaded PDF file
39  $uploadedPDFs = array_filter($upload->getResults(), function ($uploadResult) {
41  return ($uploadResult->getMimeType() == 'application/pdf');
42  });
43  $uploadResult = count($uploadedPDFs) == 0;
44  echo json_encode(array( 'success' => $uploadResult ));
45  } catch (Exception $e) {
46  echo json_encode(array( 'success' => false ));
47  }
48  exit();
49  }
50  } else {
51  $form->setValuesByPost();
52  }
53  ilUtil::sendSuccess('Form processed successfully');
54  }
55 
56  return $form->getHTML();
57 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
This class represents a hidden form property in a property form.
if(isset($_POST['submit'])) $form
This class represents a text property in a property form.
exit
Definition: backend.php:16
Class ilFileStandardDropzoneInputGUI.
$_POST["username"]