Example #1
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('question')->isFilled(BL::err('QuestionIsRequired'));
         $this->frm->getField('answer')->isFilled(BL::err('AnswerIsRequired'));
         $this->frm->getField('categories')->isFilled(BL::err('CategoryIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['user_id'] = BackendAuthentication::getUser()->getUserId();
             $item['category_id'] = $this->frm->getField('categories')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['question'] = $this->frm->getField('question')->getValue();
             $item['answer'] = $this->frm->getField('answer')->getValue(true);
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['sequence'] = BackendFaqModel::getMaximumQuestionSequence($this->frm->getField('categories')->getValue()) + 1;
             $item['created_on'] = BackendModel::getUTCDate();
             // insert the item
             $item['id'] = BackendFaqModel::insertQuestion($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['question']) . '&highlight=row-' . $item['id']);
         }
     }
 }