public function sendAction() { $this->_sLayout = 'Frontend'; $this->_sWindowType = 'modal'; $this->_sResponse = 'ajax'; $this->_bPushMessage = true; $lsMsg = null; $loForm = Application::factory('ContactUs\\Form\\ContactUs2Form'); $loForm->setForm(); if ($this->requestIsPost()) { $loForm->setData($this->requestPost()); if ($loForm->isValid()) { $laData = $loForm->getData(); $laMsg = print_r($laData, true); $loSendMail = new SendMail(); try { $loSendMail->send(array($laData['fromMail'], $laData['fromName']), $laData['subject'], $laMsg); $lsMsg = Translator::i18n('Sua mensagem foi enviada com sucesso.'); } catch (Exception $e) { $lsMsg = sprintf('<strong>%s</strong><br/> %s<br/>%s', Translator::i18n('Opa!'), Translator::i18n('Algo de errado aconteceu. Por favor, tente novamente mais tarde.'), $e->getMessage()); } } else { Debug::display('not'); } } else { Debug::display('nao'); } $loView = new ViewModel(array('lsTitle' => $this->_sTitleS, 'lsRoute' => $this->_sRoute, 'loForm' => $loForm)); return $this->setResponseType($loView, $lsMsg); }
/** * * @return string */ public function response() { if ($this->_sResoponseType == 'json') { header("Content-Type: application/json"); return Json::encode($this->_aResponse); } elseif ($this->_sResoponseType == 'stream') { header("Content-type: text/event-stream"); $lsResponse = Json::encode($this->_aResponse); return "data: " . $lsResponse . "\n\n"; } else { Debug::display($this->_aResponse); } }