2

I added a custom field to the registration form, but only this field I want to save in my custom table, who can help? Thank you

  • 2
    Hello Robinio , you may try to use event observer i.e add event handler to registration form save event (customer_register_success). – Rahul Makwana Jan 16 '19 at 10:35
2

You can use Event observer this way Create a file Module/Custom/etc/events.xml and put this code in it

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="customer_register_success">
    <observer name="module_custom_save_customer" instance="Module\Custom\Observer\SaveCustomer" />
    </event>
</config>

Then create a SaveCustomer file in Observer directory Module/Custom/Observer/SaveCustomer.php

<?php
namespace Module\Custom\Observer;

use Magento\Framework\Event\Observer;

class SaveCustomer implements \Magento\Framework\Event\ObserverInterface
{
    protected $customerFactory;
    protected $addressFactory;
    public function __construct(
        \Magento\Customer\Model\CustomerFactory $customerFactory,
        \Magento\Customer\Model\AddressFactory $addressFactory
        ) { 
        $this->contact_list=$raveHelper->getContactList();
        $this->customerFactory = $customerFactory;
        $this->addressFactory = $addressFactory;
    }

    public function execute(Observer $observer)
    {
        // Your custom code here
    }
}

To save your custom data in the custom table, can refer the below blog https://bsscommerce.com/confluence/how-to-create-insert-data-into-the-table-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.