Custom field of mobile number is not showing on registration page in Magento 2.2.5

by Bhakti Thakkar   Last Updated September 11, 2018 10:09 AM

I want to add mobile no field in registration form. here is the code

InstallData.php

<?php
/**
 * Copyright © 2016 Rouven Alexander Rieker
 * See LICENSE.md bundled with this module for license details.
 */
namespace Semaio\AdvancedLogin\Setup;

use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
 * Class InstallData
 *
 * @package Semaio\AdvancedLogin\Setup
 */
class InstallData implements InstallDataInterface
{
    /**
     * Customer setup factory
     *
     * @var \Magento\Customer\Setup\CustomerSetupFactory
     */
    private $customerSetupFactory;

    /**
     * Init
     *
     * @param \Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory
     */
    public function __construct(\Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory)
    {
        $this->customerSetupFactory = $customerSetupFactory;
    }

    /**
     * Installs DB schema for a module
     *
     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface   $context
     * @return void
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

        /** @var CustomerSetup $customerSetup */
        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

        // Add new customer attribute
        $customerSetup->addAttribute(
            Customer::ENTITY,
            'customer_number',
            [

                'label'                 => 'Customer Number',
                'input'                 => 'text',
                'required'              => false,
                'sort_order'            => 10,
                'visible'               => true,
                'system'                => false,
                'is_used_in_grid'       => true,
                'is_visible_in_grid'    => true,
                'is_filterable_in_grid' => true,
                'is_searchable_in_grid' => true
            ]
        );


        // add attribute to form
        /** @var  $attribute */
        $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'customer_number');
        $attribute->setData('used_in_forms', ['adminhtml_customer','checkout_register','customer_account_create','customer_account_edit','adminhtml_checkout']);
        $attribute->save();

        $setup->endSetup();
    }
}

view/frontend/templates/form/register.phtml

<div class="field required">
    <label for="customer_number" class="label"><span><?= __('CustomerNumber') ?></span></label>
    <div class="control">
        <input type="text" name="customer_number" id="customer_number" value="<?= $block->escapeHtml($block->getFormData()->getCustomerNumber()) ?>" title="<?= __('CustomerNumber') ?>" class="input-text" data-validate="{required:true, 'validate-phoneStrict':true}">
    </div>
</div>

can anyone help me where is the problem?



Answers 2


Template path should be

view/frontend/templates/form/register.phtml

so please change template to templates

Ansar Husain
Ansar Husain
September 11, 2018 10:01 AM

app/design/frontend/{Vendor}/{theme}/Magento_Customer/templates/form/register.phtml

<div class="field required">
    <label for="customer_number" class="label"><span><?= __('CustomerNumber') ?></span></label>
    <div class="control">
        <input type="text" name="customer_number" id="customer_number" value="<?= $block->escapeHtml($block->getFormData()->getCustomerNumber()) ?>" title="<?= __('CustomerNumber') ?>" class="input-text" data-validate="{required:true, 'validate-phoneStrict':true}">
    </div>
</div>
Prince
Prince
September 11, 2018 10:08 AM

Related Questions




Redirect Magento2 404 page to the register page

Updated May 15, 2018 17:09 PM