/** * Load the form */ private function loadForm() { // create form $this->frm = new FrontendForm('own_question', '#' . FL::getAction('OwnQuestion')); $this->frm->addText('name')->setAttribute('placeholder', FL::getLabel('YourName')); $this->frm->addText('email')->setAttribute('placeholder', FL::getLabel('YourEmail')); $this->frm->addTextarea('message')->setAttribute('placeholder', FL::getLabel('YourQuestion')); }
/** * 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 (FrontendModel::getModuleSetting('faq', 'send_email_on_new_feedback')) { // add the question $variables['question'] = $this->record['question']; // add the email FrontendMailer::addEmail(sprintf(FL::getMessage('FaqFeedbackSubject'), $this->record['question']), FRONTEND_MODULES_PATH . '/faq/layout/templates/mails/feedback.tpl', $variables); } } // trigger event FrontendModel::triggerEvent('faq', 'after_add_feedback', array('comment' => $text)); // save status $this->redirect($this->record['full_url'] . '/' . FL::getAction('Success')); } } else { $this->tpl->assign('hideFeedbackNoInfo', true); } }