Skip to content
Snippets Groups Projects
Commit 299360ea authored by Chris Hallberg's avatar Chris Hallberg Committed by Demian Katz
Browse files

Update Feedback to work with new Lightbox.

- View feedback instead of throwing
- Use of VuFind/Mailer
- Resolves VUFIND-1177
parent 62ea9d4d
Branches
Tags
No related merge requests found
......@@ -11,7 +11,7 @@
* @link https://vufind.org Main Site
*/
namespace VuFind\Controller;
use Zend\Mail as Mail;
use Zend\Mail\Address;
/**
* Feedback Class
......@@ -33,8 +33,7 @@ class FeedbackController extends AbstractBase
*/
public function homeAction()
{
// no action needed
return $this->createViewModel();
return $this->forwardTo('Feedback', 'Email');
}
/**
......@@ -45,52 +44,57 @@ class FeedbackController extends AbstractBase
*/
public function emailAction()
{
$name = $this->params()->fromPost('name');
$users_email = $this->params()->fromPost('email');
$comments = $this->params()->fromPost('comments');
// Process form submission:
if ($this->formWasSubmitted('submit')) {
$name = $this->params()->fromPost('name');
$users_email = $this->params()->fromPost('email');
$comments = $this->params()->fromPost('comments');
if (empty($name) || empty($users_email) || empty($comments)) {
throw new \Exception('Missing data.');
}
$validator = new \Zend\Validator\EmailAddress();
if (!$validator->isValid($users_email)) {
throw new \Exception('Email address is invalid');
}
// These settings are set in the feedback settion of your config.ini
$config = $this->getServiceLocator()->get('VuFind\Config')->get('config');
$feedback = isset($config->Feedback) ? $config->Feedback : null;
$recipient_email = isset($feedback->recipient_email)
? $feedback->recipient_email : null;
$recipient_name = isset($feedback->recipient_name)
? $feedback->recipient_name : 'Your Library';
$email_subject = isset($feedback->email_subject)
? $feedback->email_subject : 'VuFind Feedback';
$sender_email = isset($feedback->sender_email)
? $feedback->sender_email : 'noreply@vufind.org';
$sender_name = isset($feedback->sender_name)
? $feedback->sender_name : 'VuFind Feedback';
if ($recipient_email == null) {
throw new \Exception(
'Feedback Module Error: Recipient Email Unset (see config.ini)'
);
}
if ($comments == "") {
throw new \Exception('Feedback Module Error: Comment Post Failed');
}
if (empty($users_email) || empty($comments)) {
$this->flashMessenger()->addMessage('bulk_error_missing', 'error');
return;
}
$email_message = 'Name: ' . $name . "\n";
$email_message .= 'Email: ' . $users_email . "\n";
$email_message .= 'Comments: ' . $comments . "\n";
// These settings are set in the feedback settion of your config.ini
$config = $this->getServiceLocator()->get('VuFind\Config')
->get('config');
$feedback = isset($config->Feedback) ? $config->Feedback : null;
$recipient_email = isset($feedback->recipient_email)
? $feedback->recipient_email : null;
$recipient_name = isset($feedback->recipient_name)
? $feedback->recipient_name : 'Your Library';
$email_subject = isset($feedback->email_subject)
? $feedback->email_subject : 'VuFind Feedback';
$sender_email = isset($feedback->sender_email)
? $feedback->sender_email : 'noreply@vufind.org';
$sender_name = isset($feedback->sender_name)
? $feedback->sender_name : 'VuFind Feedback';
if ($recipient_email == null) {
throw new \Exception(
'Feedback Module Error: Recipient Email Unset (see config.ini)'
);
}
// This sets up the email to be sent
$mail = new Mail\Message();
$mail->setBody($email_message);
$mail->setFrom($sender_email, $sender_name);
$mail->addTo($recipient_email, $recipient_name);
$mail->setSubject($email_subject);
$email_message = empty($name) ? '' : 'Name: ' . $name . "\n";
$email_message .= 'Email: ' . $users_email . "\n";
$email_message .= 'Comments: ' . $comments . "\n\n";
$this->getServiceLocator()->get('VuFind\Mailer')->getTransport()
->send($mail);
// This sets up the email to be sent
// Attempt to send the email and show an appropriate flash message:
try {
$mailer = $this->getServiceLocator()->get('VuFind\Mailer');
$mailer->send(
new Address($recipient_email, $recipient_name),
new Address($sender_email, $sender_name),
$email_subject, $email_message
);
$this->flashMessenger()->addMessage(
'Thank you for your feedback.', 'success'
);
} catch (MailException $e) {
$this->flashMessenger()->addMessage($e->getMessage(), 'error');
}
return $this->createViewModel();
}
}
}
<?=$this->render('feedback/form.phtml');?>
\ No newline at end of file
<?
// Set page title
$this->headTitle($this->translate('Feedback'));
// Get rid of the feedback tab since this uses the same variables
$this->layout()->feedbacktab = false;
?>
<?=$this->render('feedback/form.phtml');?>
<h2><?=$this->transEsc("Send us your feedback!")?></h2>
<?=$this->flashmessages() ?>
<form class="form-horizontal" name="feedback" method="post" action="<?=$this->url('feedback-email')?>">
<input type="hidden" id="formSuccess" value="<?=$this->transEsc("Form Submitted!")?>"/>
<input type="hidden" id="feedbackSuccess" value="<?=$this->transEsc("Thank you for your feedback.")?>"/>
<input type="hidden" id="feedbackFailure" value="<?=$this->transEsc("An error has occurred")?>"/>
<div class="form-group">
<label class="col-sm-3 control-label" for="name"><?=$this->transEsc("feedback_name")?></label>
<div class="col-sm-9">
......@@ -12,18 +10,18 @@
<div class="form-group">
<label class="col-sm-3 control-label" for="email"><?=$this->transEsc("Email")?></label>
<div class="col-sm-9">
<input type="email" id="email" name="email" class="form-control"/>
<input type="email" id="email" name="email" class="form-control" required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="comments"><?=$this->transEsc("Comments")?></label>
<div class="col-sm-9">
<textarea id="comments" name="comments" class="form-control"></textarea>
<textarea id="comments" name="comments" class="form-control" required></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<input type="submit" class="btn btn-primary" value="<?=$this->transEsc("Send")?>" />
<input type="submit" name="submit" class="btn btn-primary" value="<?=$this->transEsc("Send")?>" />
</div>
</div>
</form>
\ No newline at end of file
</form>
<?
// Set page title
$this->headTitle($this->translate('Feedback'));
// Get rid of the feedback tab since this uses the same variables
$this->layout()->feedbacktab = false;
?>
<?=$this->render('feedback/form.phtml');?>
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