I want to add custom field in customer registration form in magento2.

I don't want to make it customer attribute and want to save in custom table.

Can anyone help me

  • Why you don't want to create an attribute, I'm curious to know reason behind it.
    – anonymous
    Commented Nov 18, 2019 at 11:47
  • 1
    Becuase I want to check on another page another to taking all customers customer field value that already exists or not!!! when we using flat table what i mean say is not eav table it quite faster than eav staructure. And client just too curious about speed Commented Nov 18, 2019 at 12:03

1 Answer 1


Create a module named Vendor_Module. Create all the files and structure like below:

Step 1:



Step 2:


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="0.0.1">
            <module name="Magento_Customer"/>

Step 3:


<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceContainer name="form.additional.info">
            <block class="Magento\Customer\Block\Form\Register" name="additional_info_customer_custom_fields" template="Vendor_Module::customer/customfields.phtml" before="-"/>

Step 4:


<div class="field custom required">
    <label for="custom" class="label"><span><?= $block->escapeHtml(__('Custom')) ?></span></label>
    <div class="control">
        <input name="custom" type="text" value="" class="input-text" autocomplete="false" title="Custom" data-validate="{required:true}" />

Step 5:


<?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="custom_register" instance="Vendor\Module\Observer\Accountcreate" shared="false" />

Step 6:


namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class Accountcreate implements ObserverInterface
    protected $request;

    public function __construct(
        ... Inject Your custom model where your want to save the data
        \Magento\Framework\App\Request\Http $request,
    ) {
        $this->request = $request;

    public function execute(Observer $observer)
        $custom = $this->request->getParam('custom');
        Now load your model and save the data, you will get the custom data in $custom field.

Run the necessary commands and test.

  • 1
    Thanks @Sukumar for the very detailed answer. will check and approve once functionality working as expected. Commented Nov 18, 2019 at 11:43
  • Hello... in step 4 you used value="" . That causes the field to be cleared if the registration form is reloaded because of an error (e.g. wrong CAPTCHA). How to set the current entered value so that user does not need to type the field value again? This feature works for default registration fields only.
    – jstuardo
    Commented Jul 23, 2021 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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