diff --git a/config/vufind/FeedbackForms.yaml b/config/vufind/FeedbackForms.yaml index 2747ebdbd275b039e23dd4c083ecb0af3adbba9f..15e91768fe8cea025474e3cc6dcc26faef35113f 100644 --- a/config/vufind/FeedbackForms.yaml +++ b/config/vufind/FeedbackForms.yaml @@ -12,6 +12,7 @@ # useCaptcha (boolean) Should the form use Captcha validation? Requires the "feedback" # option to be turned on in the config.ini [Captcha] form setting. # (default = true, if Captcha turned on for feedback overall). +# reportReferrer (boolean) Should the form report the page from which it was invoked? # title (string) Form title (translation key) # onlyForLoggedUsers (boolean) Require the user to be logged in to see the form # (default = false) @@ -49,7 +50,7 @@ # required (boolean) Is the element required? # settings (array) HTML attributes as key-value pairs, for example: # - [class, "custom-css-class another-class"] -# type (string) Element type (text|textarea|email|url|select|radio|checkbox) +# type (string) Element type (text|textarea|email|url|select|radio|checkbox|hidden) # # help (string) Element help text (translation key) that is displayed before the element. # To include HTML formatting, use a translation key ending @@ -103,6 +104,7 @@ forms: title: Send us your feedback! enabled: true useCaptcha: true + reportReferrer: false #recipient: # name: Your Library # email: feedback@myuniversity.edu diff --git a/module/VuFind/src/VuFind/Controller/FeedbackController.php b/module/VuFind/src/VuFind/Controller/FeedbackController.php index e899413e2ab5d7e9dfbcd77a418b1e7b8565f15b..d939b509f0d3e5d249a6405f76ebb5ffc1976944 100644 --- a/module/VuFind/src/VuFind/Controller/FeedbackController.php +++ b/module/VuFind/src/VuFind/Controller/FeedbackController.php @@ -55,7 +55,12 @@ class FeedbackController extends AbstractBase $user = $this->getUser(); $form = $this->serviceLocator->get(\VuFind\Form\Form::class); - $form->setFormId($formId); + $params = []; + if ($refererHeader = $this->getRequest()->getHeader('Referer') + ) { + $params['referrer'] = $refererHeader->getFieldValue(); + } + $form->setFormId($formId, $params); if (!$form->isEnabled()) { throw new \VuFind\Exception\Forbidden("Form '$formId' is disabled"); diff --git a/module/VuFind/src/VuFind/Form/Form.php b/module/VuFind/src/VuFind/Form/Form.php index 837a5bb9efb52879e6bd390b6959187dbca2f923..e83be3a9e73be06f2bfe1fe23043874facf399e6 100644 --- a/module/VuFind/src/VuFind/Form/Form.php +++ b/module/VuFind/src/VuFind/Form/Form.php @@ -124,18 +124,19 @@ class Form extends \Laminas\Form\Form implements * Set form id * * @param string $formId Form id + * @param array $params Additional form parameters. * * @return void * @throws Exception */ - public function setFormId($formId) + public function setFormId($formId, $params = []) { if (!$config = $this->getFormConfig($formId)) { throw new \VuFind\Exception\RecordMissing("Form '$formId' not found"); } $this->formElementConfig - = $this->parseConfig($formId, $config); + = $this->parseConfig($formId, $config, $params); $this->buildForm($this->formElementConfig); } @@ -204,10 +205,11 @@ class Form extends \Laminas\Form\Form implements * * @param string $formId Form id * @param array $config Configuration + * @param array $params Additional form parameters. * * @return array */ - protected function parseConfig($formId, $config) + protected function parseConfig($formId, $config, $params) { $formConfig = [ 'id' => $formId, @@ -348,6 +350,17 @@ class Form extends \Laminas\Form\Form implements $elements[] = $element; } + if ($this->reportReferrer()) { + if ($referrer = ($params['referrer'] ?? false)) { + $elements[] = [ + 'type' => 'hidden', + 'name' => 'referrer', + 'settings' => ['value' => $referrer], + 'label' => $this->translate('Referrer'), + ]; + } + } + $elements[]= [ 'type' => 'submit', 'name' => 'submit', @@ -366,7 +379,8 @@ class Form extends \Laminas\Form\Form implements { return [ 'recipient', 'title', 'help', 'submit', 'response', 'useCaptcha', - 'enabled', 'onlyForLoggedUsers', 'emailSubject', 'senderInfoRequired' + 'enabled', 'onlyForLoggedUsers', 'emailSubject', 'senderInfoRequired', + 'reportReferrer' ]; } @@ -514,7 +528,8 @@ class Form extends \Laminas\Form\Form implements 'textarea' => '\Laminas\Form\Element\Textarea', 'radio' => '\Laminas\Form\Element\Radio', 'select' => '\Laminas\Form\Element\Select', - 'submit' => '\Laminas\Form\Element\Submit' + 'submit' => '\Laminas\Form\Element\Submit', + 'hidden' => '\Laminas\Form\Element\Hidden' ]; return $map[$type] ?? null; @@ -541,6 +556,16 @@ class Form extends \Laminas\Form\Form implements return (bool)($this->formConfig['useCaptcha'] ?? true); } + /** + * Check if the form should report referrer url + * + * @return bool + */ + public function reportReferrer() + { + return (bool)($this->formConfig['reportReferrer'] ?? false); + } + /** * Check if form is available only for logged users. *