Clever works_

How to save form data to the custom table in Magento 2

Magento 2 SET DATA IN CUSTOM TABLE BY POST METHOD

To set data to our new table, we need to create a new controller Index.php in app/code/CleverCode/HelloWorld/Controller/Add with following contents:

As you can see, it will create a POST variable called name after which it will create an instance of our model by using objectManager. To set our data we need to use the magic function SetNameOfOurColumn($value) and save it. As you can see, we used a redirect to the previous page. To use that we put in ResultFactory. Instead of RefererUrl we can use this:

It will work too. To use our controller we need to add a simple form to our phtml like this:

To get the correct URL, we use the getUrl()function. We need to direct our parameters through the route. To use that we need to upgrade our script with the following command:

 

Related works_

BreakAwayDistributing B2B and B2C
selling platform

The SLK Solutions agency responsible for developing an online store hired us to help them with creating a selling platform dedicated to B2B and B2C clients. BreakAwayDistributing – agency operating from 1993 with main office located in Hamilton, Canada offers high quality products

Learn more

Internet flower shop
from SLK Solutions

SLK Solutions is an IT agency operating in the USA, which helps small and large business owners to implement new technologies. They asked us to support them with our experts with the complete implementation of an eCommerce project for their client.

Learn more