I want to add default telephone field in our website Create and Account form.

I enable Telephone field under Store >> Configuration >> Customer >> Customer Configuration >> Name & Address Option >> Show Telephone (Required). But not show Telephone field in create customer account page. How can i show for it?


  • You have to create a custom module for that Commented Mar 19, 2021 at 5:57
  • just change to default theme (luma) and check if you can see it...
    – Pawan
    Commented Mar 19, 2021 at 6:04

1 Answer 1


First of all Create a simple module or if you are having custom module you can also use that

Create a file


Enter your own Vendor\ModuleName in namespace

namespace VendorName\ModuleName\Setup\Patch\Data;

use Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory;
use Magento\Customer\Model\Customer;
use Magento\Eav\Model\Config;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Psr\Log\LoggerInterface;

class AddPhoneAttribute implements DataPatchInterface, PatchRevertableInterface
   private $moduleDataSetup;
   private $eavSetupFactory;
   private $productCollectionFactory;
   private $logger;
   private $eavConfig;

   private $attributeResource;

   public function __construct(
       EavSetupFactory $eavSetupFactory,
       Config $eavConfig,
       LoggerInterface $logger,
       \Magento\Customer\Model\ResourceModel\Attribute $attributeResource,
       \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
   ) {
       $this->eavSetupFactory = $eavSetupFactory;
       $this->eavConfig = $eavConfig;
       $this->logger = $logger;
       $this->attributeResource = $attributeResource;
       $this->moduleDataSetup = $moduleDataSetup;

   public function apply()

   public function addPhoneAttribute()
       $eavSetup = $this->eavSetupFactory->create();

               'type' => 'varchar',
               'label' => 'Phone Number',
               'input' => 'text',
               'required' => 1,
               'visible' => 1,
               'user_defined' => 1,
               'sort_order' => 999,
               'position' => 999,
               'system' => 0

       $attributeSetId = $eavSetup->getDefaultAttributeSetId(Customer::ENTITY);
       $attributeGroupId = $eavSetup->getDefaultAttributeGroupId(Customer::ENTITY);

       $attribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'phone_number');
       $attribute->setData('attribute_set_id', $attributeSetId);
       $attribute->setData('attribute_group_id', $attributeGroupId);

       $attribute->setData('used_in_forms', [


   public static function getDependencies()
       return [];

   public function revert()
       public function getAliases()
       return [];

Create another file view/frontend/layout/customer_account_create.xml Change Vendorname_Modulename with your own Vendor_Module

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       <referenceContainer name="form.additional.info">
           <block class="Magento\Framework\View\Element\Template"

Create another file view/frontend/templates/extra_field.phtml

<div class="field phone_number required">
   <label class="label" for="phone_number">
       <span><?= $block->escapeHtml(__('Phone number')) ?></span>
   <div class="control">
       <input type="text" name="phone_number" id="phone_number" value="" title="<?= $block->escapeHtmlAttr(__('Phone number')) ?>" class="input-text" data-validate="{required:true}">

Now run and field will added to your registration form

php bin/magento setup:upgrade && php bin/magento setup:di:compile && php bin/magento s:s:d -f && php bin/magento cache:flush

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.