Exemple #1
0
 /**
  * Submits the form
  */
 public function submit()
 {
     $this->check();
     if (count($this->_errors) == 0) {
         // Valid form
         switch ($this->_action) {
             case self::ACTION_EMAIL:
                 // Send the form
                 if (!$this->_recipient) {
                     throw new \Exception($this->_exceptions[Form::EXCEPTION_INVALID_EMAIL], Form::EXCEPTION_INVALID_EMAIL);
                 }
                 $emldata = array('bodytext' => $this->_bodytext, 'title' => $this->_title, 'fields' => $this->_data);
                 $smarty = new \Smarty();
                 $ds = DIRECTORY_SEPARATOR;
                 $smarty->assign($emldata)->setCacheDir(BASEPATH . "bright{$ds}cache{$ds}smarty")->setCompileDir(BASEPATH . "bright{$ds}cache{$ds}smarty_c")->enableSecurity()->addTemplateDir(BASEPATH . "bright{$ds}library{$ds}Bright{$ds}templates{$ds}")->registerPlugin(\Smarty::PLUGIN_FUNCTION, 'getLabel', array($this, '_getLabel'))->registerPlugin(\Smarty::PLUGIN_FUNCTION, 'getValue', array($this, '_getValue'))->php_handling = \Smarty::PHP_REMOVE;
                 ob_start();
                 $smarty->display('FormMailTemplate.tpl');
                 $html = ob_get_clean();
                 ob_start();
                 $smarty->display('FormMailPlainTemplate.tpl');
                 $plain = ob_get_clean();
                 $mailer = new Mailer();
                 $res = $mailer->sendHtmlMail(MAILINGFROM, $this->_recipient, $this->_subject, $html, $plain);
                 if ($res && $this->_pageAfterSuccess != null) {
                     $t = new Tree();
                     $path = $t->getPath($this->_pageAfterSuccess);
                     if (USEPREFIX) {
                         $path = $_SESSION['language'] . '/' . $path;
                     }
                     $path = BASEURL . $path;
                     header("Location: {$path}");
                     exit;
                 }
                 break;
             case self::ACTION_STORE:
                 // Store the data
                 throw new \Exception($this->_exceptions[Form::EXCEPTION_NOT_IMPLEMENTED] . ' ACTION_STORE', Form::EXCEPTION_NOT_IMPLEMENTED);
                 break;
         }
     }
     return $this;
 }