17 use Psr\Log\LoggerInterface;
26 private $dataPersistor;
55 LoggerInterface $logger =
null 57 parent::__construct($context, $contactsConfig);
58 $this->context = $context;
60 $this->dataPersistor = $dataPersistor;
61 $this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
72 return $this->resultRedirectFactory->create()->setPath(
'*/*/');
75 $this->sendEmail($this->validatedParams());
76 $this->messageManager->addSuccessMessage(
77 __(
'Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')
79 $this->dataPersistor->clear(
'contact_us');
81 $this->messageManager->addErrorMessage($e->getMessage());
82 $this->dataPersistor->set(
'contact_us', $this->
getRequest()->getParams());
83 }
catch (\Exception $e) {
84 $this->logger->critical($e);
85 $this->messageManager->addErrorMessage(
86 __(
'An error occurred while processing your form. Please try again later.')
88 $this->dataPersistor->set(
'contact_us', $this->
getRequest()->getParams());
90 return $this->resultRedirectFactory->create()->setPath(
'contact/index');
97 private function sendEmail($post)
109 private function validatedParams()
112 if (trim(
$request->getParam(
'name')) ===
'') {
113 throw new LocalizedException(
__(
'Enter the Name and try again.'));
115 if (trim(
$request->getParam(
'comment')) ===
'') {
116 throw new LocalizedException(
__(
'Enter the comment and try again.'));
118 if (
false === \strpos(
$request->getParam(
'email'),
'@')) {
119 throw new LocalizedException(
__(
'The email address is invalid. Verify the email address and try again.'));
121 if (trim(
$request->getParam(
'hideit')) !==
'') {
122 throw new \Exception();
__construct(Context $context, ConfigInterface $contactsConfig, MailInterface $mail, DataPersistorInterface $dataPersistor, LoggerInterface $logger=null)