Skip to content
Snippets Groups Projects
Commit c94fb39c authored by Alexander Purr's avatar Alexander Purr Committed by Dorian Merz
Browse files

refs #16020 [fid_adlr] add contact form

* add receiver information to config.ini
* add 2 forms configurations to FeedbackForms.yaml
* include FeedbackController in module.config.php
* add extended FeedbackController
* add 2 form templates
* add translations
parent 1cf706d7
Branches
Tags
No related merge requests found
---
# Listing of configured forms.
#
# Configured forms are listed in the top level 'forms' array and can accessed via the URL:
# /Feedback/Form/<form-id>
#
# The main Feedback form (id: FeedbackSite) can be accessed with a shorter URL /Feedback
#
# Form supports the following options:
#
# enabled (boolean) Is the form enabled? (default = true)
# 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).
# title (string) Form title (translation key)
# onlyForLoggedUsers (boolean) Require the user to be logged in to see the form
# (default = false)
# 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%%)
# that are replaced with submitted form values.
# recipient
# name (string) Recipient name (default = recipient_name setting from config.ini
# [Feedback] section)
# email (string) Recipient email address (default = recipient_email setting from
# config.ini [Feedback] section)
# response (string) Reponse after form submit (translation key)
# senderInfoRequired (boolean) Require sender to fill out name and email fields
#
# help
# pre (string) Help text displayed at the beginning of the form (translation key).
# post (string) Help text displayed at the end of the form (translation key)
#
# Help texts may contain HTML-formatting.
#
# fields (array) List of form elements with the following options:
#
# name (string) Element name
# label (string) Element label (translation key)
# 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)
# help (string) Element help text (translation key)
#
# And for select elements one of:
#
# options (array) List of select values (translation keys)
#
# or
#
# optionGroups (array) List of option groups with keys:
# label (string) Group label (translation key)
# options (array) List of select values (translation keys)
#
#-----------------------------------------------------------------------------------
forms:
## Preselect Feedback options
PreselectSite:
title: Contact
enabled: true
useCaptcha: false
fields:
- name: emailSubject
type: select
label: email_subject
required: true
options:
- general_question
- catalogue_error
- account_question
- resource_not_found
- purchase_request
# Main Feedback form
FeedbackSite:
title: Contact
enabled: true
useCaptcha: false
emailSubject: %%emailSubject%%
recipient:
name: FID adlr.link
email: stoppe@ub.uni-leipzig.de
onlyForLoggedUsers: false
response: Thank you for your feedback.
senderInfoRequired: true
fields:
- name: emailSubject
type: select
label: email_subject
settings:
- [disabled, "disabled"]
options:
- general_question
- catalogue_error
- account_question
- resource_not_found
- purchase_request
- name: message
type: textarea
label: Message
required: true
\ No newline at end of file
---
# Listing of configured forms.
#
# Configured forms are listed in the top level 'forms' array and can accessed via the URL:
# /Feedback/Form/<form-id>
#
# The main Feedback form (id: FeedbackSite) can be accessed with a shorter URL /Feedback
#
# Form supports the following options:
#
# enabled (boolean) Is the form enabled? (default = true)
# 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).
# title (string) Form title (translation key)
# onlyForLoggedUsers (boolean) Require the user to be logged in to see the form
# (default = false)
# 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%%)
# that are replaced with submitted form values.
# recipient
# name (string) Recipient name (default = recipient_name setting from config.ini
# [Feedback] section)
# email (string) Recipient email address (default = recipient_email setting from
# config.ini [Feedback] section)
# response (string) Reponse after form submit (translation key)
# senderInfoRequired (boolean) Require sender to fill out name and email fields
#
# help
# pre (string) Help text displayed at the beginning of the form (translation key).
# post (string) Help text displayed at the end of the form (translation key)
#
# Help texts may contain HTML-formatting.
#
# fields (array) List of form elements with the following options:
#
# name (string) Element name
# label (string) Element label (translation key)
# 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)
# help (string) Element help text (translation key)
#
# And for select elements one of:
#
# options (array) List of select values (translation keys)
#
# or
#
# optionGroups (array) List of option groups with keys:
# label (string) Group label (translation key)
# options (array) List of select values (translation keys)
#
#-----------------------------------------------------------------------------------
forms:
## Preselect Feedback options
PreselectSite:
title: Contact
enabled: true
useCaptcha: false
fields:
- name: emailSubject
type: select
label: email_subject
required: true
options:
- general_question
- catalogue_error
- account_question
- resource_not_found
- purchase_request
# Main Feedback form
FeedbackSite:
title: Contact
enabled: true
useCaptcha: false
emailSubject: %%emailSubject%%
recipient:
name: FID adlr.link
email: stoppe@ub.uni-leipzig.de
onlyForLoggedUsers: false
response: Thank you for your feedback.
senderInfoRequired: true
fields:
- name: emailSubject
type: select
label: email_subject
settings:
- [disabled, "disabled"]
options:
- general_question
- catalogue_error
- account_question
- resource_not_found
- purchase_request
- name: message
type: textarea
label: Message
required: true
\ No newline at end of file
......@@ -109,3 +109,11 @@ xml_doc = "blog_adlr_link_feed.xml"
;[RecordPermissions]
;WorldcatTab[] = "getSourceID:0"
[Feedback]
tab_enabled=true
recipient_email="stoppe@ub.uni-leipzig.de"
recipient_name="adlr.link Dr. Sebastian Stoppe"
email_subject="%%emailSubject%%"
sender_name="adlr.link Feedback"
sender_email="noreply@adlr.link"
\ No newline at end of file
......@@ -23,6 +23,7 @@
use fid_adlr\Controller\MyResearchController;
use fid_adlr\Controller\MyResearchControllerFactory;
use fid_adlr\Helper\Rss;
use fid_adlr\Controller\FeedbackController;
use fid\FormModel\PasswordChangeModel;
use Zend\Router\Http\Regex;
use Zend\ServiceManager\Factory\InvokableFactory;
......@@ -36,10 +37,13 @@ $config = [
],
'controllers' => [
'factories' => [
MyResearchController::class => MyResearchControllerFactory::class
MyResearchController::class => MyResearchControllerFactory::class,
FeedbackController::class => 'VuFind\Controller\AbstractBaseFactory',
],
'aliases' => [
'my-research' => MyResearchController::class,
'feedback' => FeedbackController::class,
'Feedback' => FeedbackController::class
],
],
'view_helpers' => [
......
<?php
/**
* Copyright (C) 2019 Leipzig University Library
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @author Robert Lange <lange@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
*/
namespace fid_adlr\Controller;
use VuFind\Controller\FeedbackController as BaseFeedbackController;
use VuFind\Form\Form;
/**
* Redirects the user to the appropriate default VuFind action.
*
* @category VuFind
* @package Controller
* @author Robert Lange <lange@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
class FeedbackController extends BaseFeedbackController
{
/**
* Display Feedback form.
*
* @return \Zend\View\Model\ViewModel
*/
public function homeAction()
{
return $this->forwardTo('Feedback', 'Preselect');
}
/**
* Handles rendering and submit of preselect form.
* Form configurations are specified in FeedbackForms.json
*
* @return void
*/
public function preselectAction()
{
$formId = $this->params()->fromRoute('id', $this->params()->fromQuery('id'));
if (!$formId) {
$formId = 'PreselectSite';
}
$user = $this->getUser();
$form = $this->serviceLocator->get('VuFind\Form\Form');
$form->setFormId($formId);
if (!$form->isEnabled()) {
throw new \VuFind\Exception\Forbidden("Form '$formId' is disabled");
}
$view = $this->createViewModel(compact('form', 'formId', 'user'));
$view->useRecaptcha
= $this->recaptcha()->active('feedback') && $form->useCaptcha();
$params = $this->params();
$form->setData($params->fromPost());
if (!$this->formWasSubmitted('submit', $view->useRecaptcha)) {
$form = $this->prefillUserInfo($form, $user);
return $view;
}
if (! $form->isValid()) {
return $view;
}
return $view;
}
/**
* Handles rendering and submit of the real feedback form.
* Form configurations are specified in FeedbackForms.json
*
* @return void
*/
public function formAction()
{
$formId = $this->params()->fromRoute('id', $this->params()->fromQuery('id'));
if (!$formId || $formId == "PreselectSite") {
$formId = 'FeedbackSite';
}
$user = $this->getUser();
$form = $this->serviceLocator->get('VuFind\Form\Form');
$form->setFormId($formId);
if (!$form->isEnabled()) {
throw new \VuFind\Exception\Forbidden("Form '$formId' is disabled");
}
$view = $this->createViewModel(compact('form', 'formId', 'user'));
$view->useRecaptcha
= $this->recaptcha()->active('feedback') && $form->useCaptcha();
//$params = ;
$postParams = $this->params()->fromPost();
$result = $this->followup()->retrieve("emailSubject");
if ( !isset($postParams["emailSubject"]) && isset($result) ) {
$postParams["emailSubject"] = $result;
}
else $this->followup()->store(["emailSubject" => $postParams["emailSubject"]]);
$form->setData($postParams);
// force login if NOT general question or catalogue error
$emailSubject = $postParams["emailSubject"];
if ($emailSubject != "general_question" && $emailSubject != "catalogue_error" ) {
if (!$user)
return $this->forceLogin(null,["emailSubject" => $emailSubject]);
}
if ($user && ! $form->isValid()) {
$form = $this->prefillUserInfo($form, $user);
return $view;
}
if (! $form->isValid()) {
return $view;
}
// remove followup session parameter
$this->followup()->clear("emailSubject");
//prepare Mail
list($messageParams, $template) = $form->formatEmailMessage($postParams);
$emailMessage = $this->getViewRenderer()->partial( $template, ['fields' => $messageParams]);
list($senderName, $senderEmail) = $this->getSender();
$replyToName = $postParams["name"];
$replyToEmail = $postParams["email"];
list($recipientName, $recipientEmail) = $form->getRecipient();
$emailSubject = $form->getEmailSubject($postParams);
list($success, $errorMsg) = $this->sendEmail(
$recipientName, $recipientEmail, $senderName, $senderEmail,
$replyToName, $replyToEmail, $emailSubject, $emailMessage
);
$this->showResponse($view, $form, $success, $errorMsg);
return $view;
}
}
......@@ -57,4 +57,14 @@ Adlr Home Services Resources Title = "adlr.link lizenziert Ressourcen"
Adlr Home Services Resources Text = "Über adlr.link haben alle Nutzerinnen und Nutzer, die hauptberuflich in der Wissenschaft arbeiten, Zugriff auf die spezielle FID-Lizenzen. Außerdem haben wir ein ständig wachsendes Angebot an eigens für adlr.link lizenzierten E-Books."
# 16180
error_password_pattern = "Das Passwort muss mindestens eine Ziffer und einen Großbuchstaben enthalten."
\ No newline at end of file
error_password_pattern = "Das Passwort muss mindestens eine Ziffer und einen Großbuchstaben enthalten."
; feedback form
feedback_information = "Finden Sie einen bestimmten Titel nicht oder haben Sie einen Anschaffungswunsch? Haben Sie Fragen zu Ihrem Konto oder zur Registrierung oder eine allgemeine Frage?"
email_contact_policy = "Ich habe die %%policy_link%% gelesen und bin damit einverstanden."
; feedback form options
general_question = "Ich habe eine allgemeine Frage."
catalogue_error = "Ich habe einen Fehler im Katalog gefunden."
account_question = "Ich habe eine Frage zu meinem Konto."
resource_not_found = "Ich habe eine Ressource nicht gefunden."
purchase_request = "Ich habe einen Anschaffungswunsch."
\ No newline at end of file
......@@ -54,4 +54,14 @@ Adlr Home Services Resources Title = "adlr.link licenses resources"
Adlr Home Services Resources Text = "Via adlr.link, all users who work full-time in science have access to special FID licenses. In addition, we have a constantly growing range of e-books licensed specifically for adlr.link."
# 16180
error_password_pattern = "The password needs to contain at least one digit and one capital letter."
\ No newline at end of file
error_password_pattern = "The password needs to contain at least one digit and one capital letter."
; feedback form
feedback_information = "Can't find a particular resource or do you have questions about your account or another concern? Write to our team and we will help you quickly and easily."
email_contact_policy = "I have read and agree to the %%policy_link%%."
; feedback form options
general_question = "I have a general question."
catalogue_error = "I found an error in the catalogue."
account_question = "I have a question about my account."
resource_not_found = "I didn't find a resource."
purchase_request = "I have a purchase request."
\ No newline at end of file
<?php
$form = $this->form;
$form->prepare();
$title = $form->getTitle();
$title = !empty($title)
? $this->transEsc($title) : null;
$formUrl = $this->url('feedback-form', ['id' => $this->formId]);
$form->setAttribute('action', $formUrl);
$form->setAttribute('class', 'dynamic-form');
$form->setAttribute('method', 'post');
$help = $form->getHelp();
$helpPre = $helpPost = null;
$helpPre = isset($help['pre']) ? $this->translate($help['pre']) : null;
$helpPost = isset($help['post']) ? $this->translate($help['post']) : null;
?>
<div class="feedback-content">
<?php if ($title): ?>
<?php $this->headTitle($title); ?>
<h1><?=$title?></h1>
<?php endif; ?>
<?=$this->flashmessages()?>
<?php if ($form->showOnlyForLoggedUsers() && !$this->user): ?>
<div class="form-group">
<p><?=$this->translate('feedback_login_required')?></p>
<a href="<?=$this->url('myresearch-userlogin') ?>" class="btn btn-primary" data-lightbox title="Login"><i class="fa fa-sign-in" aria-hidden="true" data-lightbox-onclose="window.location.href='<?=$this->escapeHtmlAttr($formUrl) ?>'"></i> <?=$this->transEsc("Login") ?></a>
</div>
<?php else: ?>
<?= $this->form()->openTag($form); ?>
<?php if ($helpPre): ?>
<div class="form-group">
<div class="form-info pre">
<?=$helpPre?>
</div>
</div>
<?php endif ?>
<?php $currentGroup = null; ?>
<?php $countElements = count($form->getElements()); $counter = 0 ?>
<?php foreach($form->getElements() as $el): ?>
<? $counter++; ?>
<? if($counter == $countElements) : ?>
<div class="form-group">
<input id="confirmPrivacy" name="confirmPrivacy" type="checkbox" class="margin-r-2" required>
<label for="confirmPrivacy">
<?=
$this->translate(
'email_contact_policy',
['%%policy_link%%' => '<a target="_blank" href="'. $this->url('fid/user/policy') . '">' . $this->transEsc('fid::policy') . '</a>']
);
?>*
</label>
</div>
<?php endif ?>
<?php
$formElement = $form->get($el['name']);
// Group form elements into field sets
$handleGroup = $group = null;
if (isset($el['group']) && !empty($el['group'])) {
$group = $el['group'];
}
if ($group && $currentGroup === null) {
$handleGroup = 'open';
$currentGroup = $group;
} elseif ($currentGroup && !$group) {
$handleGroup = 'close';
$currentGroup = null;
} elseif ($currentGroup !== $group) {
$handleGroup = 'openAndClose';
$currentGroup = $group;
}
?>
<?php if (in_array($handleGroup, ['close', 'openAndClose'])): ?>
</div>
<?php endif ?>
<?php if (in_array($handleGroup, ['open', 'openAndClose'])): ?>
<div class="field-set">
<?php endif ?>
<div class="form-group">
<?php if (!empty($el['help'])): ?>
<p class="info"><?= $this->transEsc($el['help']) ?></p>
<?php endif ?>
<?php if ($el['type'] !== 'submit'): ?>
<label for="<?=$this->escapeHtmlAttr($el['name'])?>" class="control-label<?=!empty($el['required']) ? ' required' : ''?>"><?=$this->transEsc($el['label'])?>:</label>
<?php else: ?>
<?php if ($helpPost): ?>
<div class="form-info post">
<?=$helpPost?>
</div>
<?php endif ?>
<?=$this->recaptcha()->html($this->useRecaptcha) ?>
<?php endif ?>
<?= $this->formRow($formElement) ?>
</div>
<?php endforeach ?>
<?= $this->form()->closeTag() ?>
<?php endif ?>
</div>
<?php
$form = $this->form;
$form->prepare();
$title = $form->getTitle();
$title = !empty($title)
? $this->transEsc($title) : null;
$formUrl = $this->url('feedback-form', ['id' => $this->formId]);
$form->setAttribute('action', $formUrl);
$form->setAttribute('class', 'dynamic-form');
$form->setAttribute('method', 'post');
$help = $form->getHelp();
$helpPre = $helpPost = null;
$helpPre = isset($help['pre']) ? $this->translate($help['pre']) : null;
$helpPost = isset($help['post']) ? $this->translate($help['post']) : null;
?>
<div class="feedback-content">
<?php if ($title): ?>
<?php $this->headTitle($title); ?>
<h1><?=$title?></h1>
<?php endif; ?>
<?=$this->flashmessages()?>
<span><?=$this->translate('feedback_information')?></span>
<?php if ($form->showOnlyForLoggedUsers() && !$this->user): ?>
<div class="form-group">
<p><?=$this->translate('feedback_login_required')?></p>
<a href="<?=$this->url('myresearch-userlogin') ?>" class="btn btn-primary" data-lightbox title="Login"><i class="fa fa-sign-in" aria-hidden="true" data-lightbox-onclose="window.location.href='<?=$this->escapeHtmlAttr($formUrl) ?>'"></i> <?=$this->transEsc("Login") ?></a>
</div>
<?php else: ?>
<?= $this->form()->openTag($form); ?>
<?php if ($helpPre): ?>
<div class="form-group">
<div class="form-info pre">
<?=$helpPre?>
</div>
</div>
<?php endif ?>
<?php $currentGroup = null; ?>
<?php $countElements = count($form->getElements()); $counter = 0 ?>
<?php foreach($form->getElements() as $el): ?>
<?php if($el['name'] != "email" AND $el['name'] != "name"): ?>
<?php
$formElement = $form->get($el['name']);
// Group form elements into field sets
$handleGroup = $group = null;
if (isset($el['group']) && !empty($el['group'])) {
$group = $el['group'];
}
if ($group && $currentGroup === null) {
$handleGroup = 'open';
$currentGroup = $group;
} elseif ($currentGroup && !$group) {
$handleGroup = 'close';
$currentGroup = null;
} elseif ($currentGroup !== $group) {
$handleGroup = 'openAndClose';
$currentGroup = $group;
}
?>
<?php if (in_array($handleGroup, ['close', 'openAndClose'])): ?>
</div>
<?php endif ?>
<?php if (in_array($handleGroup, ['open', 'openAndClose'])): ?>
<div class="field-set">
<?php endif ?>
<div class="form-group">
<?php if (!empty($el['help'])): ?>
<p class="info"><?= $this->transEsc($el['help']) ?></p>
<?php endif ?>
<?php if ($el['type'] !== 'submit'): ?>
<label for="<?=$this->escapeHtmlAttr($el['name'])?>" class="control-label<?=!empty($el['required']) ? ' required' : ''?>"><?=$this->transEsc($el['label'])?>:</label>
<?php else: ?>
<?php if ($helpPost): ?>
<div class="form-info post">
<?=$helpPost?>
</div>
<?php endif ?>
<?=$this->recaptcha()->html($this->useRecaptcha) ?>
<?php endif ?>
<?= $this->formRow($formElement) ?>
</div>
<?php endif ?>
<?php endforeach ?>
<?= $this->form()->closeTag() ?>
<?php endif ?>
</div>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment