0

I have created a input type text i want to grab the data from that input and save that as a category name . I have a template simply where i am creating form and input and submit button. and i am taking value of input in block . look at the code please you will understand it more clearly .. app/code/Mastering/SampleModule/Block/Hello.php

    <?php 

namespace Mastering\SampleModule\Block;
use Magento\Framework\View\Element\Template;
use Mastering\SampleModule\Model\ResourceModel\Item\Collection;
use Mastering\SampleModule\Model\ResourceModel\Item\CollectionFactory;
use Magento\Framework\Catalog\CategoryFactory ;

class Hello extends Template {
    private $cf;
    private $messageManager;
    public function __construct(Template\Context $context , CollectionFactory $collectionfactory , \Magento\Framework\Message\ManagerInterface $messageManager , array $data = [] ){
        $this->cf = $collectionfactory ;
        parent::__construct($context,$data);
        //$this->messageManager=$messageManager;

    }
    public function getItemsResults(){
        return $this->cf->create()->getItems();
    }
    public function getFormData(){
        $post=$this->getRequest()->getPost();
        if(!empty($post)){
            $name=$post['name'];
            //$this->messageManager->addSuccessManager("data saved");
        }
    }
}
  • Do you mean you enter a name and that will create category in magento? – Rohan Hapani Oct 2 '18 at 4:48
  • Vendor_Name/Module_Name/view/adminhtml/ui_component folder create a file called category_form.xml and populate it with the xml – Aditya Shah Oct 2 '18 at 5:12

Your Answer

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

Browse other questions tagged or ask your own question.