/** * Validate the form */ private function validateForm() { $feedbackAllowed = isset($this->settings['allow_feedback']) && $this->settings['allow_feedback']; if (!$feedbackAllowed) { return false; } if ($this->frm->isSubmitted()) { // reformat data $useful = $this->frm->getField('useful')->getValue() == 'Y'; // the form has been sent $this->tpl->assign('hideFeedbackNoInfo', $useful); // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate required fields if (!$useful) { $this->frm->getField('message')->isFilled(FL::err('FeedbackIsRequired')); } if ($this->frm->isCorrect()) { // reformat data $text = $this->frm->getField('message')->getValue(); // get feedback in session $previousFeedback = \SpoonSession::exists('faq_feedback_' . $this->record['id']) ? \SpoonSession::get('faq_feedback_' . $this->record['id']) : null; // update counters FrontendFaqModel::updateFeedback($this->record['id'], $useful, $previousFeedback); // save feedback in session \SpoonSession::set('faq_feedback_' . $this->record['id'], $useful); // answer is yes so there's no feedback if (!$useful) { // get module setting $spamFilterEnabled = isset($this->settings['spamfilter']) && $this->settings['spamfilter']; // build array $variables['question_id'] = $this->record['id']; $variables['sentOn'] = time(); $variables['text'] = $text; // should we check if the item is spam if ($spamFilterEnabled) { // the comment is spam if (FrontendModel::isSpam($text, $variables['question_link'])) { // set the status to spam $this->redirect($this->record['full_url'] . '/' . FL::getAction('Spam')); } } // save the feedback FrontendFaqModel::saveFeedback($variables); // send email on new feedback? if ($this->get('fork.settings')->get('Faq', 'send_email_on_new_feedback')) { // add the question $variables['question'] = $this->record['question']; $to = $this->get('fork.settings')->get('Core', 'mailer_to'); $from = $this->get('fork.settings')->get('Core', 'mailer_from'); $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to'); $message = Message::newInstance(sprintf(FL::getMessage('FaqFeedbackSubject'), $this->record['question']))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Faq/Layout/Templates/Mails/Feedback.html.twig', $variables, true); $this->get('mailer')->send($message); } } // trigger event FrontendModel::triggerEvent('Faq', 'after_add_feedback', array('comment' => $text)); // save status $this->redirect($this->record['full_url'] . '/' . FL::getAction('Success')); } } else { // form hasn't been sent $this->tpl->assign('hideFeedbackNoInfo', true); } }