cancel
Showing results for 
Search instead for 
Did you mean: 

How to create Tel phone field on user signup form page

How to create Tel phone field on user signup form page

Hi 
I am new to Magento. i want to add tel phone filed on customer signup form.

i enable from the store -> configuration -> customer ->  

Screenshot mg- mobile set .png

1 REPLY 1

Re: How to create Tel phone field on user signup form page

Hello @sanjaymakw0653 

 

You need to insert the required field(telephone in your case) into the table. I will always encourage to accomplish this using a custom module

Create a standard module with minimal required files.

Create InstallData.php in the following path NameSpace\ModuleName\Setup

namespace NameSpace\ModuleName\Setup;

  use Magento\Customer\Setup\CustomerSetupFactory;

  use Magento\Customer\Model\Customer;

  use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;

  use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;

  use Magento\Framework\Setup\InstallDataInterface;

  use Magento\Framework\Setup\ModuleContextInterface;

  use Magento\Framework\Setup\ModuleDataSetupInterface;

  class InstallData implements InstallDataInterface

  {

 

      /**

       * CustomerSetupFactory

       * @var CustomerSetupFactory

       */

      protected $customerSetupFactory;

 

      /**

       * $attributeSetFactory

       * @var AttributeSetFactory

       */

      private $attributeSetFactory;

 

      /**

       * initiate object

       * @param CustomerSetupFactory $customerSetupFactory

       * @param AttributeSetFactory $attributeSetFactory

       */

      public function __construct(

          CustomerSetupFactory $customerSetupFactory,

          AttributeSetFactory $attributeSetFactory

      )

      {

          $this->customerSetupFactory = $customerSetupFactory;

          $this->attributeSetFactory = $attributeSetFactory;

      }

 

      /**

       * install data method

       * @param ModuleDataSetupInterface $setup

       * @param ModuleContextInterface $context

       */

      public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

      {

          $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

          $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');

          $attributeSetId = $customerEntity->getDefaultAttributeSetId();

          $attributeSet = $this->attributeSetFactory->create();

          $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

          $customerSetup->addAttribute(Customer::ENTITY, 'telephone', [

              'type' => 'varchar',

              'label' => 'Telephone',

              'input' => 'text',

              'required' => true,

              'visible' => true,

              'user_defined' => true,

              'sort_order' => 1000,

              'position' => 1000,

              'system' => 0,

          ]);

          $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'telephone')

              ->addData([

                  'attribute_set_id' => $attributeSetId,

                  'attribute_group_id' => $attributeGroupId,

                  'used_in_forms' => ['adminhtml_customer', 'customer_account_create'],

              ]);

          $attribute->save();

      }

  }

 

Add the field to the frontend by copying module-customer/view/frontend/templates/form/register.phtml to app/design/frontend/namespace/theme/Magento_Customer/templates/form/register.phtml

 

 <div class="field required">

        <label for="telephone" class="label"><span><?= __('Telephone') ?></span></label>

        <div class="control">

        <input type="text" name="telephone" id="telephone" value="<?php echo $block->escapeHtml($block->getFormData()->getTelephone()) ?>" title="<?php echo __('Telephone') ?>" class="input-text" data-validate="{required:true, 'validate-phoneStrict':true}">

        </div>

        </div>

 

 

 

Hope it helps ! 

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

 

 

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9