aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/forms/Form.php
diff options
context:
space:
mode:
authorMichaela Brückner <brueckner@data-quest.de>2024-01-02 08:55:04 +0000
committerMichaela Brückner <brueckner@data-quest.de>2024-01-02 08:55:04 +0000
commit502e6a104f200acc2f8ff81ba09257a6035406e5 (patch)
tree6c10c6662c822475c92814ec32d60951eda9cad8 /lib/classes/forms/Form.php
parentb6bdba58a8e090cb144bae382457c2e439d8a72a (diff)
new registry formular, re #1559
Closes #3533 Merge request studip/studip!1141
Diffstat (limited to 'lib/classes/forms/Form.php')
-rw-r--r--lib/classes/forms/Form.php71
1 files changed, 66 insertions, 5 deletions
diff --git a/lib/classes/forms/Form.php b/lib/classes/forms/Form.php
index 49713b7..3b29552 100644
--- a/lib/classes/forms/Form.php
+++ b/lib/classes/forms/Form.php
@@ -17,6 +17,8 @@ class Form extends Part
protected $save_button_text = '';
protected $save_button_name = '';
+ protected $cancel_button_text = '';
+ protected $cancel_button_name = '';
protected $autoStore = false;
protected $debugmode = false;
protected $success_message = '';
@@ -207,6 +209,31 @@ class Form extends Part
return $this->save_button_name ?: $this->getSaveButtonText();
}
+ public function setCancelButtonText(string $text): Form
+ {
+ $this->cancel_button_text = $text;
+ return $this;
+ }
+
+ /**
+ * @return string The text for the "save" button in the form.
+ */
+ public function getCancelButtonText() : string
+ {
+ return $this->cancel_button_text ?: _('Abbrechen');
+ }
+
+ public function setCancelButtonName(string $name): Form
+ {
+ $this->cancel_button_name = $name;
+ return $this;
+ }
+
+ public function getCancelButtonName() : string
+ {
+ return $this->cancel_button_name ?: $this->getCancelButtonText();
+ }
+
public function setSuccessMessage(string $success_message): Form
{
$this->success_message = $success_message;
@@ -250,12 +277,35 @@ class Form extends Part
{
$this->autoStore = true;
if (\Request::isPost() && \Request::isAjax() && !\Request::isDialog()) {
- $this->store();
- if ($this->success_message) {
- \PageLayout::postSuccess($this->success_message);
+ if (\Request::submitted('STUDIPFORM_SERVERVALIDATION')) {
+ //verify the user input:
+ $output = [];
+ foreach ($this->getAllInputs() as $input) {
+ if ($input->validate) {
+ $callback = $input->getValidationCallback();
+ $value = $this->getStorableValueFromRequest($input);
+ $valid = $callback($value, $input);
+ if ($valid !== true) {
+ $output[$input->getName()] = [
+ 'name' => $input->getName(),
+ 'label' => $input->getTitle(),
+ 'error' => $callback($value, $input)
+ ];
+ }
+ }
+ }
+ echo json_encode($output);
+ page_close();
+ die();
+ } else {
+ //storing the input
+ $this->store();
+ if ($this->success_message) {
+ \PageLayout::postSuccess($this->success_message);
+ }
+ page_close();
+ die();
}
- page_close();
- die();
}
return $this;
}
@@ -325,6 +375,17 @@ class Form extends Part
$stored = 0;
+ foreach ($this->getAllInputs() as $input) {
+ if ($input->validate) {
+ $callback = $input->getValidationCallback();
+ $value = $this->getStorableValueFromRequest($input);
+ $valid = $callback($value, $input);
+ if ($valid !== true) {
+ return $stored;
+ }
+ }
+ }
+
//store by each input
$all_values = [];
foreach ($this->getAllInputs() as $input) {