Skip to main content
i have some edit the alignment
Source Link
Mohit Patel
  • 4k
  • 4
  • 24
  • 53

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.

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;

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;
}

}

<?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;

    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.

added 1997 characters in body
Source Link
Deep Shah
  • 577
  • 6
  • 32

I am created one form for contact and i want to insert form data into custom table in database in magento 2.3.5 so can anyone have idea about it then please send me solution.

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;

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;
}

}

I am created one form for contact and i want to insert form data into custom table in database in magento 2.3.5 so can anyone have idea about it then please send me solution.

Thank you in Advance.

I am created one form for contact and i want to insert form data into custom table in database in magento 2.3.5 so can anyone have idea about it then please send me solution.

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;

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;
}

}

Source Link
Deep Shah
  • 577
  • 6
  • 32

How to add Data to Custom table in database using model in magento 2.3.5

I am created one form for contact and i want to insert form data into custom table in database in magento 2.3.5 so can anyone have idea about it then please send me solution.

Thank you in Advance.