Example #1
0
 public function actionPost()
 {
     // Template
     $template_name = $this->getParam('template');
     $response = $this->getResponse();
     // we need a form_key from session to validate this come from a template form
     if ($this->getSession()->getData('_form_key') != $this->getParam('_form_key')) {
         $this->getSession()->addErrorMessage(__('Sorry. There were any errors. Please, try again in a few minutes.'));
         if ($template_name && Template::exists($template_name)) {
             $response->redirect(Template::getTemplateUrl($template_name));
         } else {
             $response->redirect(LP_URL);
         }
     } else {
         // Hooks manager
         try {
             Mvc::getModel('hooks')->exec($template_name, $_POST);
             if (isset($_POST['success_template']) && Template::exists($_POST['success_template'])) {
                 $template = $_POST['success_template'];
             } else {
                 $template = $template_name;
             }
             // TODO: get messages from form
             $this->getSession()->addSuccessMessage(__('Thank you for your submit!'));
             $response->redirect(Template::getTemplateUrl($template));
         } catch (Exception $e) {
             if (isset($_POST['error_template']) && Template::exists($_POST['error_template'])) {
                 $template = $_POST['error_template'];
             } else {
                 $template = $template_name;
             }
             $this->getSession()->addErrorMessage(__('Sorry. There were any errors. Please, try again in a few minutes.'));
             $response->redirect(Template::getTemplateUrl($template));
         }
     }
     return $response;
 }