Question

I have displayed additional fields when registering a new customer.

  • company name
  • address
  • mobile phone

I miss the "company's registration number" field

How can I create this field and display it in the registration form and client panel?

Was it helpful?

Solution

Copy core file vendor\magento\module-customer\view\frontend\templates\form\register.phtml in your current active theme

For eg.

app/design/frontend/{YOUR_PACKAGE}/{YOUR_THEME}/Magento_Customer/templates/form/register.phtml

After add below code in above file after company field (after line number 63 or 64)

<div class="field company_registration_number required">
    <label for="company_registration_number" class="label"><span><?php /* @escapeNotVerified */ echo __("Company's registration number") ?></span></label>
    <div class="control">
        <input type="text" name="company_registration_number" value="<?php echo $block->escapeHtml($block->getFormData()->getCompanyRegistrationNumber()) ?>" title="<?php /* @escapeNotVerified */ echo __("Company's registration number") ?>" id="company_registration_number" class="input-text required-entry" data-validate="{required:true}">
    </div>
</div>

After run below commands

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:clean

Note: But first create customer address attribute

Company's registration number

Here I have used attribute code company_registration_number. If you are already created then add your attribute code in above code.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top