Magento 2 - Adding custom fields to customer registration form?

Multi tool use
Multi tool use


Magento 2 - Adding custom fields to customer registration form?



I am needing to add a few custom fields to the customer registration form within Magento 2.



The fields I need to add are:



Company Registration Number, Business Type (Which will be a select list) and Sage Account Number



I've looked at a few resources and attempted to setup a customer attribute but I haven't had much luck.



This is my code so far in InstallData.php:


InstallData.php


public function __construct(CustomerSetupFactory $customerSetupFactory) {
$this->customerSetupFactory = $customerSetupFactory;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
MagentoCustomerModelCustomer::ENTITY,
'company_reg_number',
[
'type' => 'varchar',
'label' => 'Comapny Registration Number',
'input' => 'text',
'required' => true,
'visible' => true,
'user_defined' => true,
'position' => 999,
'system' => 0,
]
);

$companyRegNo = $this->eavConfig->getAttribute(Customer::ENTITY, 'company_reg_number');
// more used_in_forms ['adminhtml_checkout','adminhtml_customer','adminhtml_customer_address','customer_account_edit','customer_address_edit','customer_register_address']
$companyRegNo->setData(
'used_in_forms',
['adminhtml_customer']
);

$companyRegNo->save();
}



I expect to see a new field called Company Registration Number in the backend customer section here:



Customer Account Information backend page



enter image description here



Not sure if I'm missing something?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

nTagSI QWt9,ECaxC8fNVsP 2 MRb,MJoaSPfLcO0FzC9Uu2o JGl6u65t6dFEoVmL4 2uoT6llwLriRA
FT5ootOuZ3lrltG,tPK

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications