From da72b2476e86bfea91b367793d3e88a06d502d80 Mon Sep 17 00:00:00 2001 From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:09:58 +0200 Subject: [PATCH] Adjust Feedback/form.phtml to allow overriding the default action route (#4187) --- config/vufind/FeedbackForms.yaml | 2 ++ module/VuFind/src/VuFind/Form/Form.php | 10 ++++++++++ themes/bootstrap3/templates/feedback/form.phtml | 5 ++--- themes/bootstrap5/templates/feedback/form.phtml | 5 ++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/config/vufind/FeedbackForms.yaml b/config/vufind/FeedbackForms.yaml index f24680a9b59..574ab8abd75 100644 --- a/config/vufind/FeedbackForms.yaml +++ b/config/vufind/FeedbackForms.yaml @@ -17,6 +17,7 @@ # title (string) Form title (translation key) # onlyForLoggedUsers (boolean) Require the user to be logged in to see the form # (default = false) +# formActionRoute (string) Sets the route to which form data should be posted. (default = feedback-form) # emailSubject (string) Email subject (translation key). (default = email_subject # value from config.ini [Feedback] section, or 'VuFind Feedback') # The subject may contain placeholders (for example %%receiver%%) @@ -163,6 +164,7 @@ forms: useCaptcha: true reportReferrer: false reportUserAgent: true + #formActionRoute: controller-route #emailFrom: # name: Your Library - Site Feedback #recipient: diff --git a/module/VuFind/src/VuFind/Form/Form.php b/module/VuFind/src/VuFind/Form/Form.php index 382e3de4623..dbdc66a5360 100644 --- a/module/VuFind/src/VuFind/Form/Form.php +++ b/module/VuFind/src/VuFind/Form/Form.php @@ -252,6 +252,16 @@ public function getFormElementConfig(): array return $this->formElementConfig; } + /** + * Return form action route if set in config + * + * @return string Form action route or feedback-form as default + */ + public function getFormActionRoute(): string + { + return $this->formConfig['formActionRoute'] ?? 'feedback-form'; + } + /** * Return form recipient(s). * diff --git a/themes/bootstrap3/templates/feedback/form.phtml b/themes/bootstrap3/templates/feedback/form.phtml index a1c92d5c472..411a16f6220 100644 --- a/themes/bootstrap3/templates/feedback/form.phtml +++ b/themes/bootstrap3/templates/feedback/form.phtml @@ -3,10 +3,9 @@ $form->prepare(); $title = $form->getTitle(); - $title = !empty($title) - ? $this->translate($title) : null; + $title = !empty($title) ? $this->translate($title) : null; - $formUrl = $this->url('feedback-form', ['id' => $this->formId]); + $formUrl = $this->url($form->getFormActionRoute(), ['id' => $this->formId]); $form->setAttribute('action', $formUrl); $form->setAttribute('class', 'dynamic-form'); $form->setAttribute('method', 'post'); diff --git a/themes/bootstrap5/templates/feedback/form.phtml b/themes/bootstrap5/templates/feedback/form.phtml index a1c92d5c472..411a16f6220 100644 --- a/themes/bootstrap5/templates/feedback/form.phtml +++ b/themes/bootstrap5/templates/feedback/form.phtml @@ -3,10 +3,9 @@ $form->prepare(); $title = $form->getTitle(); - $title = !empty($title) - ? $this->translate($title) : null; + $title = !empty($title) ? $this->translate($title) : null; - $formUrl = $this->url('feedback-form', ['id' => $this->formId]); + $formUrl = $this->url($form->getFormActionRoute(), ['id' => $this->formId]); $form->setAttribute('action', $formUrl); $form->setAttribute('class', 'dynamic-form'); $form->setAttribute('method', 'post');