1

my custom_tab1.phtml my custom form is here please help me how to submit form data in custom table in magento2.3 without using objectmanager

my custom form is here please help me how to submit form data in custom table in magento2.3 without using objectmanager

0

Create a controller in your Vendor/Modlue/Controller/Index

    <?php

namespace Vendor\Module\Controller\Index;

use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\App\Action\Context;
use Vendor\Module\Model\YourModel;
class Blog extends \Magento\Framework\App\Action\Action
{
    protected $model;
    protected $date;
    protected $customermodel;

    public function __construct(
        Context $context,
        YourModel $model,
        \Magento\Framework\Stdlib\DateTime\DateTime $date
    )
    {
        $this->model = $model;
        $this->date = $date;
        parent::__construct($context);
    }

    public function execute()
    {
        $query['question'] = $this->getRequest()->getPostValue("question");
        $query['email'] = $this->getRequest()->getPostValue("email");
        $query['product_name']=$this->getRequest()->getPostValue("product_name");
        $query['cutomer_name']=$this->getRequest()->getPostValue("customer_name");

        if ($query){

        $this->model->setData($query);
        $this->model->Save();
        $redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        $redirect->setUrl($this->_redirect->getRefererUrl());
        $this->messageManager->addSuccess(__('You submitted your Question successfully.'));
        return $redirect;
        }
        else{
            $redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $redirect->setUrl($this->_redirect->getRefererUrl());
            $this->messageManager->addError (__('Failed To Submit  Please Provide Valid Data.'));
            return $redirect;
        }
    }
}
0

Review https://magento.stackexchange.com/a/222428/45214 on how to create a form and save that data in database in magento 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.