How to add Mobile custom field in Customer Registration Form?
HI @sekhar_n,
You can use following step:
- Create a custom module with default structure
- Create "etc/extension_attributes.xml" file with following code:
<?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> <extension_attributes for="Magento\Customer\Api\Data\CustomerInterface"> <attribute code="mobile" type="string"/> </extension_attributes> </config>
- Create "Setup/InstallData.php" file with following code:
<?php namespace VP\CustomerAttribute\Setup; // Change namespace and Module name use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Customer\Model\Customer; use Magento\Customer\Setup\CustomerSetupFactory; class InstallData implements InstallDataInterface { private $customerSetupFactory; /** * Constructor * * @param \Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory */ public function __construct( CustomerSetupFactory $customerSetupFactory ) { $this->customerSetupFactory = $customerSetupFactory; } /** * {@inheritdoc} */ public function install( ModuleDataSetupInterface $setup, ModuleContextInterface $context ) { $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); $customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'mobile', [ 'type' => 'varchar', 'label' => 'Mobile', 'input' => 'text', 'source' => '', 'required' => true, 'visible' => true, 'position' => 333, 'system' => false, 'backend' => '' ]); $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'mobile') ->addData(['used_in_forms' => [ 'adminhtml_customer', 'adminhtml_checkout', 'customer_account_create', 'customer_account_edit' ] ]); $attribute->save(); } }
- Install module
- Clear cache
I hope it will help you!
Hi @sekhar_n,
Did it work for you?
No
Hi @sekhar_n,
I have uploaded module for you on drive.
You can download from below url:
https://drive.google.com/file/d/1r8fFgBXSkuLm4NKbjvOhjutuzXZsOhDR/view?usp=sharing
Install it on your magento setup.
chmod -R 0777 var/ pub/ generated/ rm -rf var/cache/* pub/static/* generated/* php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy php bin/magento indexer:reindex php bin/magento cache:flush chmod -R 0777 var/ pub/ generated/
Let me know if still you face any issue.
I hope it will help you!
Did it work for you?
or still facing any issue?
it is showing in backend and in registration form it is not showing.
i have followed your steps only
i am using magento 2.3
I have just tested, it is working fine in magento2.3 as well.
are you using different language pack?
then you need to deploy static-content for language pack as well?
Please test once in default magento2.3 to make sure. There may be some issue with your theme or cache etc...