Thank you in Advance.
<?php
namespace Aspl\Contact\Controller\Ajax;
use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\Controller\Result\JsonFactory; use Magento\Framework\View\Result\PageFactory; use Aspl\Contact\Model\ContactFactory;
class ContDet extends Action { protected $_pageFactory;
namespace Aspl\Contact\Controller\Ajax;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\View\Result\PageFactory;
use Aspl\Contact\Model\ContactFactory;
class ContDet extends Action
{
protected $_pageFactory;
protected $_resultPageFactory;
protected $_resultJsonFactory;
protected $contactFactory;
public function __construct(
Context $context, ContactFactory $contactFactory, PageFactory $resultPageFactory, JsonFactory $resultJsonFactory)
{
$this->contactFactory = $contactFactory;
$this->_resultPageFactory = $resultPageFactory;
$this->_resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);
}
public function execute()
{
$result = $this->_resultJsonFactory->create();
$resultPage = $this->_resultPageFactory->create();
try {
$data = $this->getRequest()->getParams('data');
$model = $this->contactFactory->create();
//save data to variables
$model->setName($data['name']);
$model->setContact($data['contact']);
$model->setAddress($data['address']);
$model->setComments($data['comments']);
$model->save();
$response = [
'errors' => false,
'message' => __('Please Wait our Service team can contact you as soon as possible.')
];
}
catch (\Exception $e)
{
$response = [
'errors' => true,
'message' => __('Invalid Contact Details.').$e->getMessage()
];
}
return $result;
}
}
} Thank you in Advance.