From 13b2598871914bafdb585fe98d3ae345d2631a8a Mon Sep 17 00:00:00 2001 From: David Siegfried <david.siegfried@uni-vechta.de> Date: Fri, 21 Jul 2023 07:46:33 +0000 Subject: [PATCH] add data-secure to form, closes #2907 Closes #2907 Merge request studip/studip!1961 --- lib/classes/forms/Form.php | 16 ++++++++++++++++ templates/forms/form.php | 1 + 2 files changed, 17 insertions(+) diff --git a/lib/classes/forms/Form.php b/lib/classes/forms/Form.php index 892e144533f..0afe442b536 100644 --- a/lib/classes/forms/Form.php +++ b/lib/classes/forms/Form.php @@ -22,6 +22,7 @@ class Form extends Part protected $success_message = ''; protected $collapsable = false; + protected $data_secure = true; //to identify a form element protected $id = null; @@ -276,6 +277,21 @@ class Form extends Part return $this; } + /** + * Sets if the form should be secured against accidental leaving of the page. Standard is on. + * @param $data_secure + * @return $this + */ + public function setDataSecure($data_secure) + { + $this->data_secure = $data_secure; + return $this; + } + + public function getDataSecure() { + return $this->data_secure; + } + /** * Sets the ID if this form. This ID is only relevant for plugins to identify this Form object. * @param string|null $id diff --git a/templates/forms/form.php b/templates/forms/form.php index 094805e9e59..05b0b302fe8 100644 --- a/templates/forms/form.php +++ b/templates/forms/form.php @@ -22,6 +22,7 @@ $form_id = md5(uniqid()); <? endif ?> @submit="submit" novalidate + <?= $form->getDataSecure() ? 'data-secure' : '' ?> id="<?= htmlReady($form_id) ?>" data-inputs="<?= htmlReady(json_encode($inputs)) ?>" data-debugmode="<?= htmlReady(json_encode($form->getDebugMode())) ?>" -- GitLab