Magento2: How can i add custom Drop down field in registration formHow to Add New Fields on Registration page in magento2?Magento2 : How to show custom tables fields to system configuration drop downMagento 2 : How to Add Custom Input Field in Customer Registration FormMagento 2 how to create custom field in user registration pageMagento2 how to get options values for drop down filed at checkout page?Magento 2 : How can we display custom drop down in registration page?How can we display custom drop down in registration page?Add a drop-down field in checkout form Magento 2Magento 1.9 How to add custom field in checkout registration formAdd Country field in custom Checkout form in Magento2How to add custom field in registration form and add jquery validation in Magento2.2.5?

3D nonogram, beginner's edition

Should I share with a new service provider a bill from its competitor?

What is a macro? Difference between macro and function?

Is there a nice way to assign std::minmax(a, b) to std::tie(a, b)?

Most elegant way to write a one shot IF

What does grep -v "grep" mean and do?

I'm reinstalling my Linux desktop, how do I keep SSH logins working?

Why won't the ground take my seed?

Can a police officer film me on their personal device in my own home?

Why do user defined scalar functions require the schema?

What is the difference between handcrafted and learned features

Procedurally generate regions on island

Spicket or spigot?

Could human civilization live 150 years in a nuclear-powered aircraft carrier colony without resorting to mass killing/ cannibalism?

Mean Value Theorem: Continuous or Defined?

Why are there so many religions and gods?

Who are these Discworld wizards from this picture?

Is this hogweed?

How did researchers use to find articles before the Internet and the computer era?

Can a US President have someone sent to prison?

One folder two different locations on ubuntu 18.04

Generate and graph the Recamán Sequence

Is there a category where products don't exist because uniqueness fails?

Being paid less than a "junior" colleague



Magento2: How can i add custom Drop down field in registration form


How to Add New Fields on Registration page in magento2?Magento2 : How to show custom tables fields to system configuration drop downMagento 2 : How to Add Custom Input Field in Customer Registration FormMagento 2 how to create custom field in user registration pageMagento2 how to get options values for drop down filed at checkout page?Magento 2 : How can we display custom drop down in registration page?How can we display custom drop down in registration page?Add a drop-down field in checkout form Magento 2Magento 1.9 How to add custom field in checkout registration formAdd Country field in custom Checkout form in Magento2How to add custom field in registration form and add jquery validation in Magento2.2.5?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to add a drop down field (Account type) and get this value in admin just like other fields values.
How can i add custom field in registration form



enter image description here










share|improve this question
























  • Please follow below tutorials for the same. magento.stackexchange.com/questions/184006/…

    – nishu
    Jun 18 at 13:10

















0















I want to add a drop down field (Account type) and get this value in admin just like other fields values.
How can i add custom field in registration form



enter image description here










share|improve this question
























  • Please follow below tutorials for the same. magento.stackexchange.com/questions/184006/…

    – nishu
    Jun 18 at 13:10













0












0








0








I want to add a drop down field (Account type) and get this value in admin just like other fields values.
How can i add custom field in registration form



enter image description here










share|improve this question
















I want to add a drop down field (Account type) and get this value in admin just like other fields values.
How can i add custom field in registration form



enter image description here







magento2 registration custom-field






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 18 at 13:12









surbhi agr

61616 bronze badges




61616 bronze badges










asked Jun 18 at 13:06









Hafiz ArslanHafiz Arslan

3211 silver badge18 bronze badges




3211 silver badge18 bronze badges












  • Please follow below tutorials for the same. magento.stackexchange.com/questions/184006/…

    – nishu
    Jun 18 at 13:10

















  • Please follow below tutorials for the same. magento.stackexchange.com/questions/184006/…

    – nishu
    Jun 18 at 13:10
















Please follow below tutorials for the same. magento.stackexchange.com/questions/184006/…

– nishu
Jun 18 at 13:10





Please follow below tutorials for the same. magento.stackexchange.com/questions/184006/…

– nishu
Jun 18 at 13:10










2 Answers
2






active

oldest

votes


















0














Steps to add field in registration form:



Step 1: Create field (customer attribute) using InstallData.php



<?php
namespace <vendor_name><module>Setup;

use MagentoFrameworkModuleSetupMigration;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;

/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface

/**
* Customer setup factory
*
* @var MagentoCustomerSetupCustomerSetupFactory
*/
private $customerSetupFactory;

/**
* Init
*
* @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
*/
public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)

$this->customerSetupFactory = $customerSetupFactory;


/**
* @inheritdoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

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

$setup->startSetup();

$customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'profile_name', [
'type' => 'text',
'label' => 'Profile Name',
'input' => 'text',
'required' => 0,
'sort_order' => 110,
'visible' => 1,
'system' => 0,
'position' => 110
]);
//add attribute to attribute set
$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'profile_name');
$attribute->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']);
$attribute->save();

$setup->endSetup();




Step 2: override form/register.phtml using layout customer_account_create.xml



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_form_register">
<action method="setTemplate">
<argument name="template" xsi:type="string"><Vendor>_<module>::form/register.phtml</argument>
</action>
</referenceBlock>
</body>
</page>


Step 3: register.phtml



<?php $_helper = $this->helper('<vendor><module>HelperData'); ?>
<?php echo $block->getChildHtml('form_fields_before')?>
<?php /* Extensions placeholder */ ?>
<?php echo $block->getChildHtml('customer.form.register.extra')?>
<form class="form create account form-create-account" action="<?php /* @escapeNotVerified */ echo $block->getPostActionUrl() ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
<fieldset class="fieldset create info">
<legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Personal Information') ?></span></legend><br>
<input type="hidden" name="success_url" value="<?php /* @escapeNotVerified */ echo $block->getSuccessUrl() ?>">
<input type="hidden" name="error_url" value="<?php /* @escapeNotVerified */ echo $block->getErrorUrl() ?>">
<?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
<?php if ($block->isNewsletterEnabled()): ?>
<div class="field choice newsletter">
<input type="checkbox" name="is_subscribed" title="<?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
<label for="is_subscribed" class="label"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?></span></label>
</div>
<?php /* Extensions placeholder */ ?>
<?php echo $block->getChildHtml('customer.form.register.newsletter')?>
<?php endif ?>

<?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
<?php if ($_dob->isEnabled()): ?>
<?php echo $_dob->setDate($block->getFormData()->getDob())->toHtml() ?>
<?php endif ?>

<?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
<?php if ($_taxvat->isEnabled()): ?>
<?php echo $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
<?php endif ?>

<?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
<?php if ($_gender->isEnabled()): ?>
<?php echo $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
<?php endif ?>

<!-- Custom code for Profile-Name Field -->
<div class="field profile-name">
<label for="profile-name" class="label"><span><?php /* @escapeNotVerified */ echo __('Profile Name') ?></span></label>
<div class="control">
<input type="text" name="profile_name" id="profile-name" value="<?php echo $block->escapeHtml($block->getFormData()->getData('profile_name')) ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-text" maxlength="250">
</div>
</div>
<!-- End -->

</fieldset>
<?php if ($block->getShowAddressFields()): ?>
<fieldset class="fieldset address">
<legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Address Information') ?></span></legend><br>
<input type="hidden" name="create_address" value="1" />
<div class="field company">
<label for="company" class="label"><span><?php /* @escapeNotVerified */ echo __('Company') ?></span></label>
<div class="control">
<input type="text" name="company" id="company" value="<?php echo $block->escapeHtml($block->getFormData()->getCompany()) ?>" title="<?php /* @escapeNotVerified */ echo __('Company') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('company') ?>">
</div>
</div>
<div class="field telephone">
<label for="telephone" class="label"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label>
<div class="control">
<input type="text" name="telephone" id="telephone" value="<?php echo $block->escapeHtml($block->getFormData()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Phone Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('telephone') ?>">
</div>
</div>

<?php $_streetValidationClass = $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('street'); ?>

<div class="field street required">
<label for="street_1" class="label"><span><?php /* @escapeNotVerified */ echo __('Street Address') ?></span></label>
<div class="control">
<input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreet(0)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address') ?>" id="street_1" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
<div class="nested">
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
<?php for ($_i = 2, $_n = $this->helper('MagentoCustomerHelperAddress')->getStreetLines(); $_i <= $_n; $_i++): ?>
<div class="field additional">
<label class="label" for="street_<?php /* @escapeNotVerified */ echo $_i ?>">
<span><?php /* @escapeNotVerified */ echo __('Address') ?></span>
</label>
<div class="control">
<input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?>" id="street_<?php /* @escapeNotVerified */ echo $_i ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
</div>
</div>
<?php endfor; ?>
</div>
</div>
</div>

<div class="field required">
<label for="city" class="label"><span><?php /* @escapeNotVerified */ echo __('City') ?></span></label>
<div class="control">
<input type="text" name="city" value="<?php echo $block->escapeHtml($block->getFormData()->getCity()) ?>" title="<?php /* @escapeNotVerified */ echo __('City') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('city') ?>" id="city">
</div>
</div>

<div class="field region required">
<label for="region_id" class="label"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label>
<div class="control">
<select id="region_id" name="region_id" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="validate-select" style="display:none;">
<option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option>
</select>
<input type="text" id="region" name="region" value="<?php echo $block->escapeHtml($block->getRegion()) ?>" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('region') ?>" style="display:none;">
</div>
</div>

<div class="field zip required">
<label for="zip" class="label"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label>
<div class="control">
<input type="text" name="postcode" value="<?php echo $block->escapeHtml($block->getFormData()->getPostcode()) ?>" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('postcode') ?>">
</div>
</div>

<div class="field country required">
<label for="country" class="label"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label>
<div class="control">
<?php echo $block->getCountryHtmlSelect() ?>
</div>
</div>
<?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes');?>
<?php if ($addressAttributes): ?>
<?php $addressAttributes->setEntityType('customer_address'); ?>
<?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
<?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
<?php echo $addressAttributes->setShowContainer(false)->toHtml()?>
<?php endif;?>
<input type="hidden" name="default_billing" value="1">
<input type="hidden" name="default_shipping" value="1">
</fieldset>

<?php endif; ?>
<fieldset class="fieldset create account" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
<legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Sign-in Information') ?></span></legend><br>
<div class="field required">
<label for="email_address" class="label"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
<div class="control">
<input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $block->escapeHtml($block->getFormData()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true">
</div>
</div>
<div class="field password required" data-mage-init='"passwordStrengthIndicator": '>
<label for="password" class="label"><span><?php /* @escapeNotVerified */ echo __('Password') ?></span></label>
<div class="control">
<input type="password" name="password" id="password"
title="<?php /* @escapeNotVerified */ echo __('Password') ?>"
class="input-text"
data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
data-validate="required:true, 'validate-customer-password':true"
autocomplete="off">
<div id="password-strength-meter-container" data-role="password-strength-meter" >
<div id="password-strength-meter" class="password-strength-meter">
<?php /* @escapeNotVerified */ echo __('Password Strength'); ?>:
<span id="password-strength-meter-label" data-role="password-strength-meter-label" >
<?php /* @escapeNotVerified */ echo __('No Password'); ?>
</span>
</div>
</div>
</div>

</div>
<div class="field confirmation required">
<label for="password-confirmation" class="label"><span><?php /* @escapeNotVerified */ echo __('Confirm Password') ?></span></label>
<div class="control">
<input type="password" name="password_confirmation" title="<?php /* @escapeNotVerified */ echo __('Confirm Password') ?>" id="password-confirmation" class="input-text" data-validate="required:true, equalTo:'#password'" autocomplete="off">
</div>
</div>
<?php echo $block->getChildHtml('form_additional_info'); ?>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<button type="submit" class="action submit primary" title="<?php /* @escapeNotVerified */ echo __('Create an Account') ?>"><span><?php /* @escapeNotVerified */ echo __('Create an Account') ?></span></button>
</div>
<div class="secondary">
<a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a>
</div>
</div>
</form>
<script>
require([
'jquery',
'mage/mage'
], function($)

var dataForm = $('#form-validate');
var ignore = <?php /* @escapeNotVerified */ echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

dataForm.mage('validation',
<?php if ($_dob->isEnabled()): ?>
errorPlacement: function(error, element)
if (element.prop('id').search('full') !== -1)
var dobElement = $(element).parents('.customer-dob'),
errorClass = error.prop('class');
error.insertAfter(element.parent());
dobElement.find('.validate-custom').addClass(errorClass)
.after('<div class="' + errorClass + '"></div>');

else
error.insertAfter(element);

,
ignore: ':hidden:not(' + ignore + ')'
<?php else: ?>
ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
<?php endif ?>
).find('input:text').attr('autocomplete', 'off');

);
</script>
<?php if ($block->getShowAddressFields()): ?>
<script type="text/x-magento-init">

"#country":
"regionUpdater":
"optionalRegionAllowed": <?php /* @escapeNotVerified */ echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
"regionListId": "#region_id",
"regionInputId": "#region",
"postcodeId": "#zip",
"form": "#form-validate",
"regionJson": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
"defaultRegion": "<?php /* @escapeNotVerified */ echo $block->getFormData()->getRegionId() ?>",
"countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getCountriesWithOptionalZip(true) ?>



</script>
<?php endif; ?>


Step 4: Override edit.phtml file using customer_account_edit.xml



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
<body>
<!-- Set Custom Template for Register form -->
<referenceBlock name="customer_edit">
<action method="setTemplate">
<argument name="template" xsi:type="string"><vendor>_<Module>::form/edit.phtml</argument>
</action>
</referenceBlock>
<!-- End -->
</body>
</page>


Step 5: form/edit.phtml



<?php $_helper = $this->helper('<Vendor><Module>HelperData'); ?>
<form class="form form-edit-account" action="<?php /* @escapeNotVerified */ echo $block->getUrl('customer/account/editPost') ?>" method="post" id="form-validate" enctype="multipart/form-data" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>" autocomplete="off">
<fieldset class="fieldset info">
<?php echo $block->getBlockHtml('formkey')?>
<legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Account Information') ?></span></legend><br>
<?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getCustomer())->toHtml() ?>

<?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
<?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
<?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
<?php if ($_dob->isEnabled()): ?>
<?php echo $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
<?php endif ?>
<?php if ($_taxvat->isEnabled()): ?>
<?php echo $_taxvat->setTaxvat($block->getCustomer()->getTaxvat())->toHtml() ?>
<?php endif ?>
<?php if ($_gender->isEnabled()): ?>
<?php echo $_gender->setGender($block->getCustomer()->getGender())->toHtml() ?>
<?php endif ?>

<!-- Custom Code For Profile-Name Field -->
<div class="field" data-container="profile-name">
<?php $linkedinProfile = $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'profile_name')); ?>
<label class="label" for="profile-name">
<span>
<?php /* @escapeNotVerified */ echo __('Profile Name') ?>
</span>
</label>
<div class="control">
<input type="text" name="profile_name" id="linkedin-profile" data-input="linkedin-profile" value="<?php echo $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'linkedin_profile')); ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-file"/>
</div>
</div>
<!-- End -->
<div class="field choice">
<input type="checkbox" name="change_email" id="change-email" data-role="change-email" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Email') ?>" class="checkbox" />
<label class="label" for="change-email"><span><?php /* @escapeNotVerified */ echo __('Change Email') ?></span></label>
</div>
<div class="field choice">
<input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Password') ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox" />
<label class="label" for="change-password"><span><?php /* @escapeNotVerified */ echo __('Change Password') ?></span></label>
</div>
</fieldset>

<fieldset class="fieldset password" data-container="change-email-password">
<legend class="legend"><span data-title="change-email-password"><?php echo __('Change Email and Password') ?></span></legend><br>
<div class="field email required" data-container="change-email">
<label class="label" for="email"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
<div class="control">
<input type="email" name="email" id="email" autocomplete="email" data-input="change-email" value="<?php echo $block->escapeHtml($block->getCustomer()->getEmail()) ?>" title="<?php echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true" />
</div>
</div>
<div class="field password current required">
<label class="label" for="current-password"><span><?php echo __('Current Password') ?></span></label>
<div class="control">
<input type="password" class="input-text" name="current_password" id="current-password" data-input="current-password" autocomplete="off" />
</div>
</div>
<div class="field new password required" data-container="new-password" data-mage-init='"passwordStrengthIndicator": '>
<label class="label" for="password"><span><?php /* @escapeNotVerified */ echo __('New Password') ?></span></label>
<div class="control">
<input type="password" class="input-text" name="password" id="password"
data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
data-input="new-password"
data-validate="required:true, 'validate-customer-password':true"
autocomplete="off" />
<div id="password-strength-meter-container" data-role="password-strength-meter" >
<div id="password-strength-meter" class="password-strength-meter">
<?php echo __('Password Strength'); ?>:
<span id="password-strength-meter-label" data-role="password-strength-meter-label" >
<?php echo __('No Password'); ?>
</span>
</div>
</div>
</div>
</div>
<div class="field confirm password required" data-container="confirm-password">
<label class="label" for="password-confirmation"><span><?php echo __('Confirm New Password') ?></span></label>
<div class="control">
<input type="password" class="input-text" name="password_confirmation" id="password-confirmation"
data-input="confirm-password"
autocomplete="off" />
</div>
</div>
<?php echo $block->getChildHtml('form_additional_info'); ?>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<button type="submit" class="action save primary" title="<?php echo __('Save') ?>"><span><?php echo __('Save') ?></span></button>
</div>
<div class="secondary">
<a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php echo __('Go back') ?></span></a>
</div>
</div>
</form>
<script>
require([
"jquery",
"mage/mage"
], function($)
var dataForm = $('#form-validate');
var ignore = <?php echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

dataForm.mage('validation',
<?php if ($_dob->isEnabled()): ?>
errorPlacement: function(error, element)
if (element.prop('id').search('full') !== -1)
var dobElement = $(element).parents('.customer-dob'),
errorClass = error.prop('class');
error.insertAfter(element.parent());
dobElement.find('.validate-custom').addClass(errorClass)
.after('<div class="' + errorClass + '"></div>');

else
error.insertAfter(element);

,
ignore: ':hidden:not(' + ignore + ')'
<?php else: ?>
ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
<?php endif ?>
);
);
</script>
<script type="text/x-magento-init">

"[data-role=change-email], [data-role=change-password]":
"changeEmailPassword":
"titleChangeEmail": "<?php echo __('Change Email') ?>",
"titleChangePassword": "<?php echo __('Change Password') ?>",
"titleChangeEmailAndPassword": "<?php echo __('Change Email and Password') ?>"



</script>


Step 6: helper/data.php



<?php

namespace <Vendor><Module>Helper;

use MagentoFrameworkObjectManagerInterface;
use MagentoFrameworkAppActionAction;

class Data extends MagentoFrameworkAppHelperAbstractHelper

protected $_customerFactory;

protected $objectManager;

/**
* Initialize dependencies.
*
* @param MagentoFrameworkAppHelperContext $context
* @param MagentoCustomerModelCustomerFactory $customerFactory
*/
public function __construct(
MagentoFrameworkAppHelperContext $context,
MagentoCustomerModelCustomerFactory $customerFactory,
ObjectManagerInterface $objectManager
)
$this->_customerFactory = $customerFactory;
$this->objectManager = $objectManager;
parent::__construct($context);


/**
* @inheritdoc
*/
public function getCustomerAttributeValue($customerId, $attributeCode)

$customerObject = $this->_customerFactory->create()->load($customerId);
return $attribute = ($customerObject->getData($attributeCode)) ? $customerObject->getData($attributeCode): false;




Done!






share|improve this answer






























    0














    It looks for me that you would like to add a new customer dropdown attribute, not a custom dropdown attribute, that's a huge difference,



    Below I described how to add a new dropdown attribute to customer and display it on Registration & Customer Edit page



    To achieve that you need to create an in InstallData.php (or Upgrade.php depending on situation) file where you will place your code.



    Assuming it is InstallData.php



    use MagentoCustomerModelCustomer;
    use MagentoCustomerSetupCustomerSetupFactory;
    use MagentoFrameworkSetupModuleContextInterface;
    use MagentoFrameworkSetupModuleDataSetupInterface;

    /**
    * @param ModuleDataSetupInterface $setup
    * @param ModuleContextInterface $context
    */
    class InstallData implements InstallDataInterface
    {
    /**
    * @var CustomerSetupFactory
    */
    private $customerSetupFactory;

    /**
    * InstallData constructor.
    * @param CustomerSetupFactory $customerSetupFactory
    */
    public function __construct(
    CustomerSetupFactory $customerSetupFactory
    )
    $this->customerSetupFactory = $customerSetupFactory;


    /**
    * @param ModuleDataSetupInterface $setup
    * @param ModuleContextInterface $context
    */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

    $setup->startSetup();
    $this->createUserAttribute($setup);
    $setup->endSetup();

    /**
    * @param ModuleDataSetupInterface $setup
    */
    private function createUserAttribute(ModuleDataSetupInterface $setup)

    $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
    $customerSetup->addAttribute(
    Customer::ENTITY,
    "account_group",
    [
    'type' => 'int',
    'label' => 'Account Group',
    'input' => 'select',
    'source' => 'MagentoEavModelEntityAttributeSourceTable',
    'required' => true,
    'sort_order' => 215,
    'visible' => true,
    'position' => 215,
    'admin_checkout' => 1,
    'option' => ['values' => ['Group_1', 'Group_2']],
    'user_defined' => true,
    'visible_on_front' => true,
    'system' => 0,
    ]
    );

    $customerSetup->getEavConfig()
    ->getAttribute(Customer::ENTITY, "account_group")
    ->addData([
    'used_in_forms' =>
    ['adminhtml_customer', 'customer_account_edit', 'customer_account_create']
    ])
    ->save();



    As you can see last part: $customerSetup->getEavConfig()
    Is responsible for setting correct forms where do you want to show them to user.



    After run:
    php bin/magento setup:upgrade






    share|improve this answer



























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "479"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f278744%2fmagento2-how-can-i-add-custom-drop-down-field-in-registration-form%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Steps to add field in registration form:



      Step 1: Create field (customer attribute) using InstallData.php



      <?php
      namespace <vendor_name><module>Setup;

      use MagentoFrameworkModuleSetupMigration;
      use MagentoFrameworkSetupInstallDataInterface;
      use MagentoFrameworkSetupModuleContextInterface;
      use MagentoFrameworkSetupModuleDataSetupInterface;

      /**
      * @codeCoverageIgnore
      */
      class InstallData implements InstallDataInterface

      /**
      * Customer setup factory
      *
      * @var MagentoCustomerSetupCustomerSetupFactory
      */
      private $customerSetupFactory;

      /**
      * Init
      *
      * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
      */
      public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)

      $this->customerSetupFactory = $customerSetupFactory;


      /**
      * @inheritdoc
      * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
      */
      public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

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

      $setup->startSetup();

      $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'profile_name', [
      'type' => 'text',
      'label' => 'Profile Name',
      'input' => 'text',
      'required' => 0,
      'sort_order' => 110,
      'visible' => 1,
      'system' => 0,
      'position' => 110
      ]);
      //add attribute to attribute set
      $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'profile_name');
      $attribute->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']);
      $attribute->save();

      $setup->endSetup();




      Step 2: override form/register.phtml using layout customer_account_create.xml



      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <body>
      <referenceBlock name="customer_form_register">
      <action method="setTemplate">
      <argument name="template" xsi:type="string"><Vendor>_<module>::form/register.phtml</argument>
      </action>
      </referenceBlock>
      </body>
      </page>


      Step 3: register.phtml



      <?php $_helper = $this->helper('<vendor><module>HelperData'); ?>
      <?php echo $block->getChildHtml('form_fields_before')?>
      <?php /* Extensions placeholder */ ?>
      <?php echo $block->getChildHtml('customer.form.register.extra')?>
      <form class="form create account form-create-account" action="<?php /* @escapeNotVerified */ echo $block->getPostActionUrl() ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
      <fieldset class="fieldset create info">
      <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Personal Information') ?></span></legend><br>
      <input type="hidden" name="success_url" value="<?php /* @escapeNotVerified */ echo $block->getSuccessUrl() ?>">
      <input type="hidden" name="error_url" value="<?php /* @escapeNotVerified */ echo $block->getErrorUrl() ?>">
      <?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
      <?php if ($block->isNewsletterEnabled()): ?>
      <div class="field choice newsletter">
      <input type="checkbox" name="is_subscribed" title="<?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
      <label for="is_subscribed" class="label"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?></span></label>
      </div>
      <?php /* Extensions placeholder */ ?>
      <?php echo $block->getChildHtml('customer.form.register.newsletter')?>
      <?php endif ?>

      <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
      <?php if ($_dob->isEnabled()): ?>
      <?php echo $_dob->setDate($block->getFormData()->getDob())->toHtml() ?>
      <?php endif ?>

      <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
      <?php if ($_taxvat->isEnabled()): ?>
      <?php echo $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
      <?php endif ?>

      <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
      <?php if ($_gender->isEnabled()): ?>
      <?php echo $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
      <?php endif ?>

      <!-- Custom code for Profile-Name Field -->
      <div class="field profile-name">
      <label for="profile-name" class="label"><span><?php /* @escapeNotVerified */ echo __('Profile Name') ?></span></label>
      <div class="control">
      <input type="text" name="profile_name" id="profile-name" value="<?php echo $block->escapeHtml($block->getFormData()->getData('profile_name')) ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-text" maxlength="250">
      </div>
      </div>
      <!-- End -->

      </fieldset>
      <?php if ($block->getShowAddressFields()): ?>
      <fieldset class="fieldset address">
      <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Address Information') ?></span></legend><br>
      <input type="hidden" name="create_address" value="1" />
      <div class="field company">
      <label for="company" class="label"><span><?php /* @escapeNotVerified */ echo __('Company') ?></span></label>
      <div class="control">
      <input type="text" name="company" id="company" value="<?php echo $block->escapeHtml($block->getFormData()->getCompany()) ?>" title="<?php /* @escapeNotVerified */ echo __('Company') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('company') ?>">
      </div>
      </div>
      <div class="field telephone">
      <label for="telephone" class="label"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label>
      <div class="control">
      <input type="text" name="telephone" id="telephone" value="<?php echo $block->escapeHtml($block->getFormData()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Phone Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('telephone') ?>">
      </div>
      </div>

      <?php $_streetValidationClass = $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('street'); ?>

      <div class="field street required">
      <label for="street_1" class="label"><span><?php /* @escapeNotVerified */ echo __('Street Address') ?></span></label>
      <div class="control">
      <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreet(0)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address') ?>" id="street_1" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
      <div class="nested">
      <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
      <?php for ($_i = 2, $_n = $this->helper('MagentoCustomerHelperAddress')->getStreetLines(); $_i <= $_n; $_i++): ?>
      <div class="field additional">
      <label class="label" for="street_<?php /* @escapeNotVerified */ echo $_i ?>">
      <span><?php /* @escapeNotVerified */ echo __('Address') ?></span>
      </label>
      <div class="control">
      <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?>" id="street_<?php /* @escapeNotVerified */ echo $_i ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
      </div>
      </div>
      <?php endfor; ?>
      </div>
      </div>
      </div>

      <div class="field required">
      <label for="city" class="label"><span><?php /* @escapeNotVerified */ echo __('City') ?></span></label>
      <div class="control">
      <input type="text" name="city" value="<?php echo $block->escapeHtml($block->getFormData()->getCity()) ?>" title="<?php /* @escapeNotVerified */ echo __('City') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('city') ?>" id="city">
      </div>
      </div>

      <div class="field region required">
      <label for="region_id" class="label"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label>
      <div class="control">
      <select id="region_id" name="region_id" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="validate-select" style="display:none;">
      <option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option>
      </select>
      <input type="text" id="region" name="region" value="<?php echo $block->escapeHtml($block->getRegion()) ?>" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('region') ?>" style="display:none;">
      </div>
      </div>

      <div class="field zip required">
      <label for="zip" class="label"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label>
      <div class="control">
      <input type="text" name="postcode" value="<?php echo $block->escapeHtml($block->getFormData()->getPostcode()) ?>" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('postcode') ?>">
      </div>
      </div>

      <div class="field country required">
      <label for="country" class="label"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label>
      <div class="control">
      <?php echo $block->getCountryHtmlSelect() ?>
      </div>
      </div>
      <?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes');?>
      <?php if ($addressAttributes): ?>
      <?php $addressAttributes->setEntityType('customer_address'); ?>
      <?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
      <?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
      <?php echo $addressAttributes->setShowContainer(false)->toHtml()?>
      <?php endif;?>
      <input type="hidden" name="default_billing" value="1">
      <input type="hidden" name="default_shipping" value="1">
      </fieldset>

      <?php endif; ?>
      <fieldset class="fieldset create account" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
      <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Sign-in Information') ?></span></legend><br>
      <div class="field required">
      <label for="email_address" class="label"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
      <div class="control">
      <input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $block->escapeHtml($block->getFormData()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true">
      </div>
      </div>
      <div class="field password required" data-mage-init='"passwordStrengthIndicator": '>
      <label for="password" class="label"><span><?php /* @escapeNotVerified */ echo __('Password') ?></span></label>
      <div class="control">
      <input type="password" name="password" id="password"
      title="<?php /* @escapeNotVerified */ echo __('Password') ?>"
      class="input-text"
      data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
      data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
      data-validate="required:true, 'validate-customer-password':true"
      autocomplete="off">
      <div id="password-strength-meter-container" data-role="password-strength-meter" >
      <div id="password-strength-meter" class="password-strength-meter">
      <?php /* @escapeNotVerified */ echo __('Password Strength'); ?>:
      <span id="password-strength-meter-label" data-role="password-strength-meter-label" >
      <?php /* @escapeNotVerified */ echo __('No Password'); ?>
      </span>
      </div>
      </div>
      </div>

      </div>
      <div class="field confirmation required">
      <label for="password-confirmation" class="label"><span><?php /* @escapeNotVerified */ echo __('Confirm Password') ?></span></label>
      <div class="control">
      <input type="password" name="password_confirmation" title="<?php /* @escapeNotVerified */ echo __('Confirm Password') ?>" id="password-confirmation" class="input-text" data-validate="required:true, equalTo:'#password'" autocomplete="off">
      </div>
      </div>
      <?php echo $block->getChildHtml('form_additional_info'); ?>
      </fieldset>
      <div class="actions-toolbar">
      <div class="primary">
      <button type="submit" class="action submit primary" title="<?php /* @escapeNotVerified */ echo __('Create an Account') ?>"><span><?php /* @escapeNotVerified */ echo __('Create an Account') ?></span></button>
      </div>
      <div class="secondary">
      <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a>
      </div>
      </div>
      </form>
      <script>
      require([
      'jquery',
      'mage/mage'
      ], function($)

      var dataForm = $('#form-validate');
      var ignore = <?php /* @escapeNotVerified */ echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

      dataForm.mage('validation',
      <?php if ($_dob->isEnabled()): ?>
      errorPlacement: function(error, element)
      if (element.prop('id').search('full') !== -1)
      var dobElement = $(element).parents('.customer-dob'),
      errorClass = error.prop('class');
      error.insertAfter(element.parent());
      dobElement.find('.validate-custom').addClass(errorClass)
      .after('<div class="' + errorClass + '"></div>');

      else
      error.insertAfter(element);

      ,
      ignore: ':hidden:not(' + ignore + ')'
      <?php else: ?>
      ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
      <?php endif ?>
      ).find('input:text').attr('autocomplete', 'off');

      );
      </script>
      <?php if ($block->getShowAddressFields()): ?>
      <script type="text/x-magento-init">

      "#country":
      "regionUpdater":
      "optionalRegionAllowed": <?php /* @escapeNotVerified */ echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
      "regionListId": "#region_id",
      "regionInputId": "#region",
      "postcodeId": "#zip",
      "form": "#form-validate",
      "regionJson": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
      "defaultRegion": "<?php /* @escapeNotVerified */ echo $block->getFormData()->getRegionId() ?>",
      "countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getCountriesWithOptionalZip(true) ?>



      </script>
      <?php endif; ?>


      Step 4: Override edit.phtml file using customer_account_edit.xml



      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <update handle="customer_account"/>
      <body>
      <!-- Set Custom Template for Register form -->
      <referenceBlock name="customer_edit">
      <action method="setTemplate">
      <argument name="template" xsi:type="string"><vendor>_<Module>::form/edit.phtml</argument>
      </action>
      </referenceBlock>
      <!-- End -->
      </body>
      </page>


      Step 5: form/edit.phtml



      <?php $_helper = $this->helper('<Vendor><Module>HelperData'); ?>
      <form class="form form-edit-account" action="<?php /* @escapeNotVerified */ echo $block->getUrl('customer/account/editPost') ?>" method="post" id="form-validate" enctype="multipart/form-data" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>" autocomplete="off">
      <fieldset class="fieldset info">
      <?php echo $block->getBlockHtml('formkey')?>
      <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Account Information') ?></span></legend><br>
      <?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getCustomer())->toHtml() ?>

      <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
      <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
      <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
      <?php if ($_dob->isEnabled()): ?>
      <?php echo $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
      <?php endif ?>
      <?php if ($_taxvat->isEnabled()): ?>
      <?php echo $_taxvat->setTaxvat($block->getCustomer()->getTaxvat())->toHtml() ?>
      <?php endif ?>
      <?php if ($_gender->isEnabled()): ?>
      <?php echo $_gender->setGender($block->getCustomer()->getGender())->toHtml() ?>
      <?php endif ?>

      <!-- Custom Code For Profile-Name Field -->
      <div class="field" data-container="profile-name">
      <?php $linkedinProfile = $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'profile_name')); ?>
      <label class="label" for="profile-name">
      <span>
      <?php /* @escapeNotVerified */ echo __('Profile Name') ?>
      </span>
      </label>
      <div class="control">
      <input type="text" name="profile_name" id="linkedin-profile" data-input="linkedin-profile" value="<?php echo $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'linkedin_profile')); ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-file"/>
      </div>
      </div>
      <!-- End -->
      <div class="field choice">
      <input type="checkbox" name="change_email" id="change-email" data-role="change-email" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Email') ?>" class="checkbox" />
      <label class="label" for="change-email"><span><?php /* @escapeNotVerified */ echo __('Change Email') ?></span></label>
      </div>
      <div class="field choice">
      <input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Password') ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox" />
      <label class="label" for="change-password"><span><?php /* @escapeNotVerified */ echo __('Change Password') ?></span></label>
      </div>
      </fieldset>

      <fieldset class="fieldset password" data-container="change-email-password">
      <legend class="legend"><span data-title="change-email-password"><?php echo __('Change Email and Password') ?></span></legend><br>
      <div class="field email required" data-container="change-email">
      <label class="label" for="email"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
      <div class="control">
      <input type="email" name="email" id="email" autocomplete="email" data-input="change-email" value="<?php echo $block->escapeHtml($block->getCustomer()->getEmail()) ?>" title="<?php echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true" />
      </div>
      </div>
      <div class="field password current required">
      <label class="label" for="current-password"><span><?php echo __('Current Password') ?></span></label>
      <div class="control">
      <input type="password" class="input-text" name="current_password" id="current-password" data-input="current-password" autocomplete="off" />
      </div>
      </div>
      <div class="field new password required" data-container="new-password" data-mage-init='"passwordStrengthIndicator": '>
      <label class="label" for="password"><span><?php /* @escapeNotVerified */ echo __('New Password') ?></span></label>
      <div class="control">
      <input type="password" class="input-text" name="password" id="password"
      data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
      data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
      data-input="new-password"
      data-validate="required:true, 'validate-customer-password':true"
      autocomplete="off" />
      <div id="password-strength-meter-container" data-role="password-strength-meter" >
      <div id="password-strength-meter" class="password-strength-meter">
      <?php echo __('Password Strength'); ?>:
      <span id="password-strength-meter-label" data-role="password-strength-meter-label" >
      <?php echo __('No Password'); ?>
      </span>
      </div>
      </div>
      </div>
      </div>
      <div class="field confirm password required" data-container="confirm-password">
      <label class="label" for="password-confirmation"><span><?php echo __('Confirm New Password') ?></span></label>
      <div class="control">
      <input type="password" class="input-text" name="password_confirmation" id="password-confirmation"
      data-input="confirm-password"
      autocomplete="off" />
      </div>
      </div>
      <?php echo $block->getChildHtml('form_additional_info'); ?>
      </fieldset>
      <div class="actions-toolbar">
      <div class="primary">
      <button type="submit" class="action save primary" title="<?php echo __('Save') ?>"><span><?php echo __('Save') ?></span></button>
      </div>
      <div class="secondary">
      <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php echo __('Go back') ?></span></a>
      </div>
      </div>
      </form>
      <script>
      require([
      "jquery",
      "mage/mage"
      ], function($)
      var dataForm = $('#form-validate');
      var ignore = <?php echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

      dataForm.mage('validation',
      <?php if ($_dob->isEnabled()): ?>
      errorPlacement: function(error, element)
      if (element.prop('id').search('full') !== -1)
      var dobElement = $(element).parents('.customer-dob'),
      errorClass = error.prop('class');
      error.insertAfter(element.parent());
      dobElement.find('.validate-custom').addClass(errorClass)
      .after('<div class="' + errorClass + '"></div>');

      else
      error.insertAfter(element);

      ,
      ignore: ':hidden:not(' + ignore + ')'
      <?php else: ?>
      ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
      <?php endif ?>
      );
      );
      </script>
      <script type="text/x-magento-init">

      "[data-role=change-email], [data-role=change-password]":
      "changeEmailPassword":
      "titleChangeEmail": "<?php echo __('Change Email') ?>",
      "titleChangePassword": "<?php echo __('Change Password') ?>",
      "titleChangeEmailAndPassword": "<?php echo __('Change Email and Password') ?>"



      </script>


      Step 6: helper/data.php



      <?php

      namespace <Vendor><Module>Helper;

      use MagentoFrameworkObjectManagerInterface;
      use MagentoFrameworkAppActionAction;

      class Data extends MagentoFrameworkAppHelperAbstractHelper

      protected $_customerFactory;

      protected $objectManager;

      /**
      * Initialize dependencies.
      *
      * @param MagentoFrameworkAppHelperContext $context
      * @param MagentoCustomerModelCustomerFactory $customerFactory
      */
      public function __construct(
      MagentoFrameworkAppHelperContext $context,
      MagentoCustomerModelCustomerFactory $customerFactory,
      ObjectManagerInterface $objectManager
      )
      $this->_customerFactory = $customerFactory;
      $this->objectManager = $objectManager;
      parent::__construct($context);


      /**
      * @inheritdoc
      */
      public function getCustomerAttributeValue($customerId, $attributeCode)

      $customerObject = $this->_customerFactory->create()->load($customerId);
      return $attribute = ($customerObject->getData($attributeCode)) ? $customerObject->getData($attributeCode): false;




      Done!






      share|improve this answer



























        0














        Steps to add field in registration form:



        Step 1: Create field (customer attribute) using InstallData.php



        <?php
        namespace <vendor_name><module>Setup;

        use MagentoFrameworkModuleSetupMigration;
        use MagentoFrameworkSetupInstallDataInterface;
        use MagentoFrameworkSetupModuleContextInterface;
        use MagentoFrameworkSetupModuleDataSetupInterface;

        /**
        * @codeCoverageIgnore
        */
        class InstallData implements InstallDataInterface

        /**
        * Customer setup factory
        *
        * @var MagentoCustomerSetupCustomerSetupFactory
        */
        private $customerSetupFactory;

        /**
        * Init
        *
        * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
        */
        public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)

        $this->customerSetupFactory = $customerSetupFactory;


        /**
        * @inheritdoc
        * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
        */
        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

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

        $setup->startSetup();

        $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'profile_name', [
        'type' => 'text',
        'label' => 'Profile Name',
        'input' => 'text',
        'required' => 0,
        'sort_order' => 110,
        'visible' => 1,
        'system' => 0,
        'position' => 110
        ]);
        //add attribute to attribute set
        $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'profile_name');
        $attribute->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']);
        $attribute->save();

        $setup->endSetup();




        Step 2: override form/register.phtml using layout customer_account_create.xml



        <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <body>
        <referenceBlock name="customer_form_register">
        <action method="setTemplate">
        <argument name="template" xsi:type="string"><Vendor>_<module>::form/register.phtml</argument>
        </action>
        </referenceBlock>
        </body>
        </page>


        Step 3: register.phtml



        <?php $_helper = $this->helper('<vendor><module>HelperData'); ?>
        <?php echo $block->getChildHtml('form_fields_before')?>
        <?php /* Extensions placeholder */ ?>
        <?php echo $block->getChildHtml('customer.form.register.extra')?>
        <form class="form create account form-create-account" action="<?php /* @escapeNotVerified */ echo $block->getPostActionUrl() ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
        <fieldset class="fieldset create info">
        <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Personal Information') ?></span></legend><br>
        <input type="hidden" name="success_url" value="<?php /* @escapeNotVerified */ echo $block->getSuccessUrl() ?>">
        <input type="hidden" name="error_url" value="<?php /* @escapeNotVerified */ echo $block->getErrorUrl() ?>">
        <?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
        <?php if ($block->isNewsletterEnabled()): ?>
        <div class="field choice newsletter">
        <input type="checkbox" name="is_subscribed" title="<?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
        <label for="is_subscribed" class="label"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?></span></label>
        </div>
        <?php /* Extensions placeholder */ ?>
        <?php echo $block->getChildHtml('customer.form.register.newsletter')?>
        <?php endif ?>

        <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
        <?php if ($_dob->isEnabled()): ?>
        <?php echo $_dob->setDate($block->getFormData()->getDob())->toHtml() ?>
        <?php endif ?>

        <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
        <?php if ($_taxvat->isEnabled()): ?>
        <?php echo $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
        <?php endif ?>

        <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
        <?php if ($_gender->isEnabled()): ?>
        <?php echo $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
        <?php endif ?>

        <!-- Custom code for Profile-Name Field -->
        <div class="field profile-name">
        <label for="profile-name" class="label"><span><?php /* @escapeNotVerified */ echo __('Profile Name') ?></span></label>
        <div class="control">
        <input type="text" name="profile_name" id="profile-name" value="<?php echo $block->escapeHtml($block->getFormData()->getData('profile_name')) ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-text" maxlength="250">
        </div>
        </div>
        <!-- End -->

        </fieldset>
        <?php if ($block->getShowAddressFields()): ?>
        <fieldset class="fieldset address">
        <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Address Information') ?></span></legend><br>
        <input type="hidden" name="create_address" value="1" />
        <div class="field company">
        <label for="company" class="label"><span><?php /* @escapeNotVerified */ echo __('Company') ?></span></label>
        <div class="control">
        <input type="text" name="company" id="company" value="<?php echo $block->escapeHtml($block->getFormData()->getCompany()) ?>" title="<?php /* @escapeNotVerified */ echo __('Company') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('company') ?>">
        </div>
        </div>
        <div class="field telephone">
        <label for="telephone" class="label"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label>
        <div class="control">
        <input type="text" name="telephone" id="telephone" value="<?php echo $block->escapeHtml($block->getFormData()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Phone Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('telephone') ?>">
        </div>
        </div>

        <?php $_streetValidationClass = $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('street'); ?>

        <div class="field street required">
        <label for="street_1" class="label"><span><?php /* @escapeNotVerified */ echo __('Street Address') ?></span></label>
        <div class="control">
        <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreet(0)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address') ?>" id="street_1" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
        <div class="nested">
        <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
        <?php for ($_i = 2, $_n = $this->helper('MagentoCustomerHelperAddress')->getStreetLines(); $_i <= $_n; $_i++): ?>
        <div class="field additional">
        <label class="label" for="street_<?php /* @escapeNotVerified */ echo $_i ?>">
        <span><?php /* @escapeNotVerified */ echo __('Address') ?></span>
        </label>
        <div class="control">
        <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?>" id="street_<?php /* @escapeNotVerified */ echo $_i ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
        </div>
        </div>
        <?php endfor; ?>
        </div>
        </div>
        </div>

        <div class="field required">
        <label for="city" class="label"><span><?php /* @escapeNotVerified */ echo __('City') ?></span></label>
        <div class="control">
        <input type="text" name="city" value="<?php echo $block->escapeHtml($block->getFormData()->getCity()) ?>" title="<?php /* @escapeNotVerified */ echo __('City') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('city') ?>" id="city">
        </div>
        </div>

        <div class="field region required">
        <label for="region_id" class="label"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label>
        <div class="control">
        <select id="region_id" name="region_id" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="validate-select" style="display:none;">
        <option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option>
        </select>
        <input type="text" id="region" name="region" value="<?php echo $block->escapeHtml($block->getRegion()) ?>" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('region') ?>" style="display:none;">
        </div>
        </div>

        <div class="field zip required">
        <label for="zip" class="label"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label>
        <div class="control">
        <input type="text" name="postcode" value="<?php echo $block->escapeHtml($block->getFormData()->getPostcode()) ?>" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('postcode') ?>">
        </div>
        </div>

        <div class="field country required">
        <label for="country" class="label"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label>
        <div class="control">
        <?php echo $block->getCountryHtmlSelect() ?>
        </div>
        </div>
        <?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes');?>
        <?php if ($addressAttributes): ?>
        <?php $addressAttributes->setEntityType('customer_address'); ?>
        <?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
        <?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
        <?php echo $addressAttributes->setShowContainer(false)->toHtml()?>
        <?php endif;?>
        <input type="hidden" name="default_billing" value="1">
        <input type="hidden" name="default_shipping" value="1">
        </fieldset>

        <?php endif; ?>
        <fieldset class="fieldset create account" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
        <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Sign-in Information') ?></span></legend><br>
        <div class="field required">
        <label for="email_address" class="label"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
        <div class="control">
        <input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $block->escapeHtml($block->getFormData()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true">
        </div>
        </div>
        <div class="field password required" data-mage-init='"passwordStrengthIndicator": '>
        <label for="password" class="label"><span><?php /* @escapeNotVerified */ echo __('Password') ?></span></label>
        <div class="control">
        <input type="password" name="password" id="password"
        title="<?php /* @escapeNotVerified */ echo __('Password') ?>"
        class="input-text"
        data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
        data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
        data-validate="required:true, 'validate-customer-password':true"
        autocomplete="off">
        <div id="password-strength-meter-container" data-role="password-strength-meter" >
        <div id="password-strength-meter" class="password-strength-meter">
        <?php /* @escapeNotVerified */ echo __('Password Strength'); ?>:
        <span id="password-strength-meter-label" data-role="password-strength-meter-label" >
        <?php /* @escapeNotVerified */ echo __('No Password'); ?>
        </span>
        </div>
        </div>
        </div>

        </div>
        <div class="field confirmation required">
        <label for="password-confirmation" class="label"><span><?php /* @escapeNotVerified */ echo __('Confirm Password') ?></span></label>
        <div class="control">
        <input type="password" name="password_confirmation" title="<?php /* @escapeNotVerified */ echo __('Confirm Password') ?>" id="password-confirmation" class="input-text" data-validate="required:true, equalTo:'#password'" autocomplete="off">
        </div>
        </div>
        <?php echo $block->getChildHtml('form_additional_info'); ?>
        </fieldset>
        <div class="actions-toolbar">
        <div class="primary">
        <button type="submit" class="action submit primary" title="<?php /* @escapeNotVerified */ echo __('Create an Account') ?>"><span><?php /* @escapeNotVerified */ echo __('Create an Account') ?></span></button>
        </div>
        <div class="secondary">
        <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a>
        </div>
        </div>
        </form>
        <script>
        require([
        'jquery',
        'mage/mage'
        ], function($)

        var dataForm = $('#form-validate');
        var ignore = <?php /* @escapeNotVerified */ echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

        dataForm.mage('validation',
        <?php if ($_dob->isEnabled()): ?>
        errorPlacement: function(error, element)
        if (element.prop('id').search('full') !== -1)
        var dobElement = $(element).parents('.customer-dob'),
        errorClass = error.prop('class');
        error.insertAfter(element.parent());
        dobElement.find('.validate-custom').addClass(errorClass)
        .after('<div class="' + errorClass + '"></div>');

        else
        error.insertAfter(element);

        ,
        ignore: ':hidden:not(' + ignore + ')'
        <?php else: ?>
        ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
        <?php endif ?>
        ).find('input:text').attr('autocomplete', 'off');

        );
        </script>
        <?php if ($block->getShowAddressFields()): ?>
        <script type="text/x-magento-init">

        "#country":
        "regionUpdater":
        "optionalRegionAllowed": <?php /* @escapeNotVerified */ echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
        "regionListId": "#region_id",
        "regionInputId": "#region",
        "postcodeId": "#zip",
        "form": "#form-validate",
        "regionJson": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
        "defaultRegion": "<?php /* @escapeNotVerified */ echo $block->getFormData()->getRegionId() ?>",
        "countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getCountriesWithOptionalZip(true) ?>



        </script>
        <?php endif; ?>


        Step 4: Override edit.phtml file using customer_account_edit.xml



        <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <update handle="customer_account"/>
        <body>
        <!-- Set Custom Template for Register form -->
        <referenceBlock name="customer_edit">
        <action method="setTemplate">
        <argument name="template" xsi:type="string"><vendor>_<Module>::form/edit.phtml</argument>
        </action>
        </referenceBlock>
        <!-- End -->
        </body>
        </page>


        Step 5: form/edit.phtml



        <?php $_helper = $this->helper('<Vendor><Module>HelperData'); ?>
        <form class="form form-edit-account" action="<?php /* @escapeNotVerified */ echo $block->getUrl('customer/account/editPost') ?>" method="post" id="form-validate" enctype="multipart/form-data" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>" autocomplete="off">
        <fieldset class="fieldset info">
        <?php echo $block->getBlockHtml('formkey')?>
        <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Account Information') ?></span></legend><br>
        <?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getCustomer())->toHtml() ?>

        <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
        <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
        <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
        <?php if ($_dob->isEnabled()): ?>
        <?php echo $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
        <?php endif ?>
        <?php if ($_taxvat->isEnabled()): ?>
        <?php echo $_taxvat->setTaxvat($block->getCustomer()->getTaxvat())->toHtml() ?>
        <?php endif ?>
        <?php if ($_gender->isEnabled()): ?>
        <?php echo $_gender->setGender($block->getCustomer()->getGender())->toHtml() ?>
        <?php endif ?>

        <!-- Custom Code For Profile-Name Field -->
        <div class="field" data-container="profile-name">
        <?php $linkedinProfile = $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'profile_name')); ?>
        <label class="label" for="profile-name">
        <span>
        <?php /* @escapeNotVerified */ echo __('Profile Name') ?>
        </span>
        </label>
        <div class="control">
        <input type="text" name="profile_name" id="linkedin-profile" data-input="linkedin-profile" value="<?php echo $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'linkedin_profile')); ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-file"/>
        </div>
        </div>
        <!-- End -->
        <div class="field choice">
        <input type="checkbox" name="change_email" id="change-email" data-role="change-email" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Email') ?>" class="checkbox" />
        <label class="label" for="change-email"><span><?php /* @escapeNotVerified */ echo __('Change Email') ?></span></label>
        </div>
        <div class="field choice">
        <input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Password') ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox" />
        <label class="label" for="change-password"><span><?php /* @escapeNotVerified */ echo __('Change Password') ?></span></label>
        </div>
        </fieldset>

        <fieldset class="fieldset password" data-container="change-email-password">
        <legend class="legend"><span data-title="change-email-password"><?php echo __('Change Email and Password') ?></span></legend><br>
        <div class="field email required" data-container="change-email">
        <label class="label" for="email"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
        <div class="control">
        <input type="email" name="email" id="email" autocomplete="email" data-input="change-email" value="<?php echo $block->escapeHtml($block->getCustomer()->getEmail()) ?>" title="<?php echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true" />
        </div>
        </div>
        <div class="field password current required">
        <label class="label" for="current-password"><span><?php echo __('Current Password') ?></span></label>
        <div class="control">
        <input type="password" class="input-text" name="current_password" id="current-password" data-input="current-password" autocomplete="off" />
        </div>
        </div>
        <div class="field new password required" data-container="new-password" data-mage-init='"passwordStrengthIndicator": '>
        <label class="label" for="password"><span><?php /* @escapeNotVerified */ echo __('New Password') ?></span></label>
        <div class="control">
        <input type="password" class="input-text" name="password" id="password"
        data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
        data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
        data-input="new-password"
        data-validate="required:true, 'validate-customer-password':true"
        autocomplete="off" />
        <div id="password-strength-meter-container" data-role="password-strength-meter" >
        <div id="password-strength-meter" class="password-strength-meter">
        <?php echo __('Password Strength'); ?>:
        <span id="password-strength-meter-label" data-role="password-strength-meter-label" >
        <?php echo __('No Password'); ?>
        </span>
        </div>
        </div>
        </div>
        </div>
        <div class="field confirm password required" data-container="confirm-password">
        <label class="label" for="password-confirmation"><span><?php echo __('Confirm New Password') ?></span></label>
        <div class="control">
        <input type="password" class="input-text" name="password_confirmation" id="password-confirmation"
        data-input="confirm-password"
        autocomplete="off" />
        </div>
        </div>
        <?php echo $block->getChildHtml('form_additional_info'); ?>
        </fieldset>
        <div class="actions-toolbar">
        <div class="primary">
        <button type="submit" class="action save primary" title="<?php echo __('Save') ?>"><span><?php echo __('Save') ?></span></button>
        </div>
        <div class="secondary">
        <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php echo __('Go back') ?></span></a>
        </div>
        </div>
        </form>
        <script>
        require([
        "jquery",
        "mage/mage"
        ], function($)
        var dataForm = $('#form-validate');
        var ignore = <?php echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

        dataForm.mage('validation',
        <?php if ($_dob->isEnabled()): ?>
        errorPlacement: function(error, element)
        if (element.prop('id').search('full') !== -1)
        var dobElement = $(element).parents('.customer-dob'),
        errorClass = error.prop('class');
        error.insertAfter(element.parent());
        dobElement.find('.validate-custom').addClass(errorClass)
        .after('<div class="' + errorClass + '"></div>');

        else
        error.insertAfter(element);

        ,
        ignore: ':hidden:not(' + ignore + ')'
        <?php else: ?>
        ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
        <?php endif ?>
        );
        );
        </script>
        <script type="text/x-magento-init">

        "[data-role=change-email], [data-role=change-password]":
        "changeEmailPassword":
        "titleChangeEmail": "<?php echo __('Change Email') ?>",
        "titleChangePassword": "<?php echo __('Change Password') ?>",
        "titleChangeEmailAndPassword": "<?php echo __('Change Email and Password') ?>"



        </script>


        Step 6: helper/data.php



        <?php

        namespace <Vendor><Module>Helper;

        use MagentoFrameworkObjectManagerInterface;
        use MagentoFrameworkAppActionAction;

        class Data extends MagentoFrameworkAppHelperAbstractHelper

        protected $_customerFactory;

        protected $objectManager;

        /**
        * Initialize dependencies.
        *
        * @param MagentoFrameworkAppHelperContext $context
        * @param MagentoCustomerModelCustomerFactory $customerFactory
        */
        public function __construct(
        MagentoFrameworkAppHelperContext $context,
        MagentoCustomerModelCustomerFactory $customerFactory,
        ObjectManagerInterface $objectManager
        )
        $this->_customerFactory = $customerFactory;
        $this->objectManager = $objectManager;
        parent::__construct($context);


        /**
        * @inheritdoc
        */
        public function getCustomerAttributeValue($customerId, $attributeCode)

        $customerObject = $this->_customerFactory->create()->load($customerId);
        return $attribute = ($customerObject->getData($attributeCode)) ? $customerObject->getData($attributeCode): false;




        Done!






        share|improve this answer

























          0












          0








          0







          Steps to add field in registration form:



          Step 1: Create field (customer attribute) using InstallData.php



          <?php
          namespace <vendor_name><module>Setup;

          use MagentoFrameworkModuleSetupMigration;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @codeCoverageIgnore
          */
          class InstallData implements InstallDataInterface

          /**
          * Customer setup factory
          *
          * @var MagentoCustomerSetupCustomerSetupFactory
          */
          private $customerSetupFactory;

          /**
          * Init
          *
          * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
          */
          public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)

          $this->customerSetupFactory = $customerSetupFactory;


          /**
          * @inheritdoc
          * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
          */
          public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

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

          $setup->startSetup();

          $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'profile_name', [
          'type' => 'text',
          'label' => 'Profile Name',
          'input' => 'text',
          'required' => 0,
          'sort_order' => 110,
          'visible' => 1,
          'system' => 0,
          'position' => 110
          ]);
          //add attribute to attribute set
          $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'profile_name');
          $attribute->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']);
          $attribute->save();

          $setup->endSetup();




          Step 2: override form/register.phtml using layout customer_account_create.xml



          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <body>
          <referenceBlock name="customer_form_register">
          <action method="setTemplate">
          <argument name="template" xsi:type="string"><Vendor>_<module>::form/register.phtml</argument>
          </action>
          </referenceBlock>
          </body>
          </page>


          Step 3: register.phtml



          <?php $_helper = $this->helper('<vendor><module>HelperData'); ?>
          <?php echo $block->getChildHtml('form_fields_before')?>
          <?php /* Extensions placeholder */ ?>
          <?php echo $block->getChildHtml('customer.form.register.extra')?>
          <form class="form create account form-create-account" action="<?php /* @escapeNotVerified */ echo $block->getPostActionUrl() ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
          <fieldset class="fieldset create info">
          <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Personal Information') ?></span></legend><br>
          <input type="hidden" name="success_url" value="<?php /* @escapeNotVerified */ echo $block->getSuccessUrl() ?>">
          <input type="hidden" name="error_url" value="<?php /* @escapeNotVerified */ echo $block->getErrorUrl() ?>">
          <?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
          <?php if ($block->isNewsletterEnabled()): ?>
          <div class="field choice newsletter">
          <input type="checkbox" name="is_subscribed" title="<?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
          <label for="is_subscribed" class="label"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?></span></label>
          </div>
          <?php /* Extensions placeholder */ ?>
          <?php echo $block->getChildHtml('customer.form.register.newsletter')?>
          <?php endif ?>

          <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
          <?php if ($_dob->isEnabled()): ?>
          <?php echo $_dob->setDate($block->getFormData()->getDob())->toHtml() ?>
          <?php endif ?>

          <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
          <?php if ($_taxvat->isEnabled()): ?>
          <?php echo $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
          <?php endif ?>

          <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
          <?php if ($_gender->isEnabled()): ?>
          <?php echo $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
          <?php endif ?>

          <!-- Custom code for Profile-Name Field -->
          <div class="field profile-name">
          <label for="profile-name" class="label"><span><?php /* @escapeNotVerified */ echo __('Profile Name') ?></span></label>
          <div class="control">
          <input type="text" name="profile_name" id="profile-name" value="<?php echo $block->escapeHtml($block->getFormData()->getData('profile_name')) ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-text" maxlength="250">
          </div>
          </div>
          <!-- End -->

          </fieldset>
          <?php if ($block->getShowAddressFields()): ?>
          <fieldset class="fieldset address">
          <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Address Information') ?></span></legend><br>
          <input type="hidden" name="create_address" value="1" />
          <div class="field company">
          <label for="company" class="label"><span><?php /* @escapeNotVerified */ echo __('Company') ?></span></label>
          <div class="control">
          <input type="text" name="company" id="company" value="<?php echo $block->escapeHtml($block->getFormData()->getCompany()) ?>" title="<?php /* @escapeNotVerified */ echo __('Company') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('company') ?>">
          </div>
          </div>
          <div class="field telephone">
          <label for="telephone" class="label"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label>
          <div class="control">
          <input type="text" name="telephone" id="telephone" value="<?php echo $block->escapeHtml($block->getFormData()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Phone Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('telephone') ?>">
          </div>
          </div>

          <?php $_streetValidationClass = $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('street'); ?>

          <div class="field street required">
          <label for="street_1" class="label"><span><?php /* @escapeNotVerified */ echo __('Street Address') ?></span></label>
          <div class="control">
          <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreet(0)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address') ?>" id="street_1" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
          <div class="nested">
          <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
          <?php for ($_i = 2, $_n = $this->helper('MagentoCustomerHelperAddress')->getStreetLines(); $_i <= $_n; $_i++): ?>
          <div class="field additional">
          <label class="label" for="street_<?php /* @escapeNotVerified */ echo $_i ?>">
          <span><?php /* @escapeNotVerified */ echo __('Address') ?></span>
          </label>
          <div class="control">
          <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?>" id="street_<?php /* @escapeNotVerified */ echo $_i ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
          </div>
          </div>
          <?php endfor; ?>
          </div>
          </div>
          </div>

          <div class="field required">
          <label for="city" class="label"><span><?php /* @escapeNotVerified */ echo __('City') ?></span></label>
          <div class="control">
          <input type="text" name="city" value="<?php echo $block->escapeHtml($block->getFormData()->getCity()) ?>" title="<?php /* @escapeNotVerified */ echo __('City') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('city') ?>" id="city">
          </div>
          </div>

          <div class="field region required">
          <label for="region_id" class="label"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label>
          <div class="control">
          <select id="region_id" name="region_id" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="validate-select" style="display:none;">
          <option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option>
          </select>
          <input type="text" id="region" name="region" value="<?php echo $block->escapeHtml($block->getRegion()) ?>" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('region') ?>" style="display:none;">
          </div>
          </div>

          <div class="field zip required">
          <label for="zip" class="label"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label>
          <div class="control">
          <input type="text" name="postcode" value="<?php echo $block->escapeHtml($block->getFormData()->getPostcode()) ?>" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('postcode') ?>">
          </div>
          </div>

          <div class="field country required">
          <label for="country" class="label"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label>
          <div class="control">
          <?php echo $block->getCountryHtmlSelect() ?>
          </div>
          </div>
          <?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes');?>
          <?php if ($addressAttributes): ?>
          <?php $addressAttributes->setEntityType('customer_address'); ?>
          <?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
          <?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
          <?php echo $addressAttributes->setShowContainer(false)->toHtml()?>
          <?php endif;?>
          <input type="hidden" name="default_billing" value="1">
          <input type="hidden" name="default_shipping" value="1">
          </fieldset>

          <?php endif; ?>
          <fieldset class="fieldset create account" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
          <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Sign-in Information') ?></span></legend><br>
          <div class="field required">
          <label for="email_address" class="label"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
          <div class="control">
          <input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $block->escapeHtml($block->getFormData()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true">
          </div>
          </div>
          <div class="field password required" data-mage-init='"passwordStrengthIndicator": '>
          <label for="password" class="label"><span><?php /* @escapeNotVerified */ echo __('Password') ?></span></label>
          <div class="control">
          <input type="password" name="password" id="password"
          title="<?php /* @escapeNotVerified */ echo __('Password') ?>"
          class="input-text"
          data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
          data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
          data-validate="required:true, 'validate-customer-password':true"
          autocomplete="off">
          <div id="password-strength-meter-container" data-role="password-strength-meter" >
          <div id="password-strength-meter" class="password-strength-meter">
          <?php /* @escapeNotVerified */ echo __('Password Strength'); ?>:
          <span id="password-strength-meter-label" data-role="password-strength-meter-label" >
          <?php /* @escapeNotVerified */ echo __('No Password'); ?>
          </span>
          </div>
          </div>
          </div>

          </div>
          <div class="field confirmation required">
          <label for="password-confirmation" class="label"><span><?php /* @escapeNotVerified */ echo __('Confirm Password') ?></span></label>
          <div class="control">
          <input type="password" name="password_confirmation" title="<?php /* @escapeNotVerified */ echo __('Confirm Password') ?>" id="password-confirmation" class="input-text" data-validate="required:true, equalTo:'#password'" autocomplete="off">
          </div>
          </div>
          <?php echo $block->getChildHtml('form_additional_info'); ?>
          </fieldset>
          <div class="actions-toolbar">
          <div class="primary">
          <button type="submit" class="action submit primary" title="<?php /* @escapeNotVerified */ echo __('Create an Account') ?>"><span><?php /* @escapeNotVerified */ echo __('Create an Account') ?></span></button>
          </div>
          <div class="secondary">
          <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a>
          </div>
          </div>
          </form>
          <script>
          require([
          'jquery',
          'mage/mage'
          ], function($)

          var dataForm = $('#form-validate');
          var ignore = <?php /* @escapeNotVerified */ echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

          dataForm.mage('validation',
          <?php if ($_dob->isEnabled()): ?>
          errorPlacement: function(error, element)
          if (element.prop('id').search('full') !== -1)
          var dobElement = $(element).parents('.customer-dob'),
          errorClass = error.prop('class');
          error.insertAfter(element.parent());
          dobElement.find('.validate-custom').addClass(errorClass)
          .after('<div class="' + errorClass + '"></div>');

          else
          error.insertAfter(element);

          ,
          ignore: ':hidden:not(' + ignore + ')'
          <?php else: ?>
          ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
          <?php endif ?>
          ).find('input:text').attr('autocomplete', 'off');

          );
          </script>
          <?php if ($block->getShowAddressFields()): ?>
          <script type="text/x-magento-init">

          "#country":
          "regionUpdater":
          "optionalRegionAllowed": <?php /* @escapeNotVerified */ echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
          "regionListId": "#region_id",
          "regionInputId": "#region",
          "postcodeId": "#zip",
          "form": "#form-validate",
          "regionJson": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
          "defaultRegion": "<?php /* @escapeNotVerified */ echo $block->getFormData()->getRegionId() ?>",
          "countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getCountriesWithOptionalZip(true) ?>



          </script>
          <?php endif; ?>


          Step 4: Override edit.phtml file using customer_account_edit.xml



          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <update handle="customer_account"/>
          <body>
          <!-- Set Custom Template for Register form -->
          <referenceBlock name="customer_edit">
          <action method="setTemplate">
          <argument name="template" xsi:type="string"><vendor>_<Module>::form/edit.phtml</argument>
          </action>
          </referenceBlock>
          <!-- End -->
          </body>
          </page>


          Step 5: form/edit.phtml



          <?php $_helper = $this->helper('<Vendor><Module>HelperData'); ?>
          <form class="form form-edit-account" action="<?php /* @escapeNotVerified */ echo $block->getUrl('customer/account/editPost') ?>" method="post" id="form-validate" enctype="multipart/form-data" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>" autocomplete="off">
          <fieldset class="fieldset info">
          <?php echo $block->getBlockHtml('formkey')?>
          <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Account Information') ?></span></legend><br>
          <?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getCustomer())->toHtml() ?>

          <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
          <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
          <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
          <?php if ($_dob->isEnabled()): ?>
          <?php echo $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
          <?php endif ?>
          <?php if ($_taxvat->isEnabled()): ?>
          <?php echo $_taxvat->setTaxvat($block->getCustomer()->getTaxvat())->toHtml() ?>
          <?php endif ?>
          <?php if ($_gender->isEnabled()): ?>
          <?php echo $_gender->setGender($block->getCustomer()->getGender())->toHtml() ?>
          <?php endif ?>

          <!-- Custom Code For Profile-Name Field -->
          <div class="field" data-container="profile-name">
          <?php $linkedinProfile = $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'profile_name')); ?>
          <label class="label" for="profile-name">
          <span>
          <?php /* @escapeNotVerified */ echo __('Profile Name') ?>
          </span>
          </label>
          <div class="control">
          <input type="text" name="profile_name" id="linkedin-profile" data-input="linkedin-profile" value="<?php echo $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'linkedin_profile')); ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-file"/>
          </div>
          </div>
          <!-- End -->
          <div class="field choice">
          <input type="checkbox" name="change_email" id="change-email" data-role="change-email" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Email') ?>" class="checkbox" />
          <label class="label" for="change-email"><span><?php /* @escapeNotVerified */ echo __('Change Email') ?></span></label>
          </div>
          <div class="field choice">
          <input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Password') ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox" />
          <label class="label" for="change-password"><span><?php /* @escapeNotVerified */ echo __('Change Password') ?></span></label>
          </div>
          </fieldset>

          <fieldset class="fieldset password" data-container="change-email-password">
          <legend class="legend"><span data-title="change-email-password"><?php echo __('Change Email and Password') ?></span></legend><br>
          <div class="field email required" data-container="change-email">
          <label class="label" for="email"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
          <div class="control">
          <input type="email" name="email" id="email" autocomplete="email" data-input="change-email" value="<?php echo $block->escapeHtml($block->getCustomer()->getEmail()) ?>" title="<?php echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true" />
          </div>
          </div>
          <div class="field password current required">
          <label class="label" for="current-password"><span><?php echo __('Current Password') ?></span></label>
          <div class="control">
          <input type="password" class="input-text" name="current_password" id="current-password" data-input="current-password" autocomplete="off" />
          </div>
          </div>
          <div class="field new password required" data-container="new-password" data-mage-init='"passwordStrengthIndicator": '>
          <label class="label" for="password"><span><?php /* @escapeNotVerified */ echo __('New Password') ?></span></label>
          <div class="control">
          <input type="password" class="input-text" name="password" id="password"
          data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
          data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
          data-input="new-password"
          data-validate="required:true, 'validate-customer-password':true"
          autocomplete="off" />
          <div id="password-strength-meter-container" data-role="password-strength-meter" >
          <div id="password-strength-meter" class="password-strength-meter">
          <?php echo __('Password Strength'); ?>:
          <span id="password-strength-meter-label" data-role="password-strength-meter-label" >
          <?php echo __('No Password'); ?>
          </span>
          </div>
          </div>
          </div>
          </div>
          <div class="field confirm password required" data-container="confirm-password">
          <label class="label" for="password-confirmation"><span><?php echo __('Confirm New Password') ?></span></label>
          <div class="control">
          <input type="password" class="input-text" name="password_confirmation" id="password-confirmation"
          data-input="confirm-password"
          autocomplete="off" />
          </div>
          </div>
          <?php echo $block->getChildHtml('form_additional_info'); ?>
          </fieldset>
          <div class="actions-toolbar">
          <div class="primary">
          <button type="submit" class="action save primary" title="<?php echo __('Save') ?>"><span><?php echo __('Save') ?></span></button>
          </div>
          <div class="secondary">
          <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php echo __('Go back') ?></span></a>
          </div>
          </div>
          </form>
          <script>
          require([
          "jquery",
          "mage/mage"
          ], function($)
          var dataForm = $('#form-validate');
          var ignore = <?php echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

          dataForm.mage('validation',
          <?php if ($_dob->isEnabled()): ?>
          errorPlacement: function(error, element)
          if (element.prop('id').search('full') !== -1)
          var dobElement = $(element).parents('.customer-dob'),
          errorClass = error.prop('class');
          error.insertAfter(element.parent());
          dobElement.find('.validate-custom').addClass(errorClass)
          .after('<div class="' + errorClass + '"></div>');

          else
          error.insertAfter(element);

          ,
          ignore: ':hidden:not(' + ignore + ')'
          <?php else: ?>
          ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
          <?php endif ?>
          );
          );
          </script>
          <script type="text/x-magento-init">

          "[data-role=change-email], [data-role=change-password]":
          "changeEmailPassword":
          "titleChangeEmail": "<?php echo __('Change Email') ?>",
          "titleChangePassword": "<?php echo __('Change Password') ?>",
          "titleChangeEmailAndPassword": "<?php echo __('Change Email and Password') ?>"



          </script>


          Step 6: helper/data.php



          <?php

          namespace <Vendor><Module>Helper;

          use MagentoFrameworkObjectManagerInterface;
          use MagentoFrameworkAppActionAction;

          class Data extends MagentoFrameworkAppHelperAbstractHelper

          protected $_customerFactory;

          protected $objectManager;

          /**
          * Initialize dependencies.
          *
          * @param MagentoFrameworkAppHelperContext $context
          * @param MagentoCustomerModelCustomerFactory $customerFactory
          */
          public function __construct(
          MagentoFrameworkAppHelperContext $context,
          MagentoCustomerModelCustomerFactory $customerFactory,
          ObjectManagerInterface $objectManager
          )
          $this->_customerFactory = $customerFactory;
          $this->objectManager = $objectManager;
          parent::__construct($context);


          /**
          * @inheritdoc
          */
          public function getCustomerAttributeValue($customerId, $attributeCode)

          $customerObject = $this->_customerFactory->create()->load($customerId);
          return $attribute = ($customerObject->getData($attributeCode)) ? $customerObject->getData($attributeCode): false;




          Done!






          share|improve this answer













          Steps to add field in registration form:



          Step 1: Create field (customer attribute) using InstallData.php



          <?php
          namespace <vendor_name><module>Setup;

          use MagentoFrameworkModuleSetupMigration;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          /**
          * @codeCoverageIgnore
          */
          class InstallData implements InstallDataInterface

          /**
          * Customer setup factory
          *
          * @var MagentoCustomerSetupCustomerSetupFactory
          */
          private $customerSetupFactory;

          /**
          * Init
          *
          * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
          */
          public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)

          $this->customerSetupFactory = $customerSetupFactory;


          /**
          * @inheritdoc
          * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
          */
          public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

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

          $setup->startSetup();

          $customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'profile_name', [
          'type' => 'text',
          'label' => 'Profile Name',
          'input' => 'text',
          'required' => 0,
          'sort_order' => 110,
          'visible' => 1,
          'system' => 0,
          'position' => 110
          ]);
          //add attribute to attribute set
          $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'profile_name');
          $attribute->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']);
          $attribute->save();

          $setup->endSetup();




          Step 2: override form/register.phtml using layout customer_account_create.xml



          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <body>
          <referenceBlock name="customer_form_register">
          <action method="setTemplate">
          <argument name="template" xsi:type="string"><Vendor>_<module>::form/register.phtml</argument>
          </action>
          </referenceBlock>
          </body>
          </page>


          Step 3: register.phtml



          <?php $_helper = $this->helper('<vendor><module>HelperData'); ?>
          <?php echo $block->getChildHtml('form_fields_before')?>
          <?php /* Extensions placeholder */ ?>
          <?php echo $block->getChildHtml('customer.form.register.extra')?>
          <form class="form create account form-create-account" action="<?php /* @escapeNotVerified */ echo $block->getPostActionUrl() ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
          <fieldset class="fieldset create info">
          <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Personal Information') ?></span></legend><br>
          <input type="hidden" name="success_url" value="<?php /* @escapeNotVerified */ echo $block->getSuccessUrl() ?>">
          <input type="hidden" name="error_url" value="<?php /* @escapeNotVerified */ echo $block->getErrorUrl() ?>">
          <?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
          <?php if ($block->isNewsletterEnabled()): ?>
          <div class="field choice newsletter">
          <input type="checkbox" name="is_subscribed" title="<?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
          <label for="is_subscribed" class="label"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?></span></label>
          </div>
          <?php /* Extensions placeholder */ ?>
          <?php echo $block->getChildHtml('customer.form.register.newsletter')?>
          <?php endif ?>

          <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
          <?php if ($_dob->isEnabled()): ?>
          <?php echo $_dob->setDate($block->getFormData()->getDob())->toHtml() ?>
          <?php endif ?>

          <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
          <?php if ($_taxvat->isEnabled()): ?>
          <?php echo $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
          <?php endif ?>

          <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
          <?php if ($_gender->isEnabled()): ?>
          <?php echo $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
          <?php endif ?>

          <!-- Custom code for Profile-Name Field -->
          <div class="field profile-name">
          <label for="profile-name" class="label"><span><?php /* @escapeNotVerified */ echo __('Profile Name') ?></span></label>
          <div class="control">
          <input type="text" name="profile_name" id="profile-name" value="<?php echo $block->escapeHtml($block->getFormData()->getData('profile_name')) ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-text" maxlength="250">
          </div>
          </div>
          <!-- End -->

          </fieldset>
          <?php if ($block->getShowAddressFields()): ?>
          <fieldset class="fieldset address">
          <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Address Information') ?></span></legend><br>
          <input type="hidden" name="create_address" value="1" />
          <div class="field company">
          <label for="company" class="label"><span><?php /* @escapeNotVerified */ echo __('Company') ?></span></label>
          <div class="control">
          <input type="text" name="company" id="company" value="<?php echo $block->escapeHtml($block->getFormData()->getCompany()) ?>" title="<?php /* @escapeNotVerified */ echo __('Company') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('company') ?>">
          </div>
          </div>
          <div class="field telephone">
          <label for="telephone" class="label"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label>
          <div class="control">
          <input type="text" name="telephone" id="telephone" value="<?php echo $block->escapeHtml($block->getFormData()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Phone Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('telephone') ?>">
          </div>
          </div>

          <?php $_streetValidationClass = $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('street'); ?>

          <div class="field street required">
          <label for="street_1" class="label"><span><?php /* @escapeNotVerified */ echo __('Street Address') ?></span></label>
          <div class="control">
          <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreet(0)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address') ?>" id="street_1" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
          <div class="nested">
          <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
          <?php for ($_i = 2, $_n = $this->helper('MagentoCustomerHelperAddress')->getStreetLines(); $_i <= $_n; $_i++): ?>
          <div class="field additional">
          <label class="label" for="street_<?php /* @escapeNotVerified */ echo $_i ?>">
          <span><?php /* @escapeNotVerified */ echo __('Address') ?></span>
          </label>
          <div class="control">
          <input type="text" name="street[]" value="<?php echo $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>" title="<?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?>" id="street_<?php /* @escapeNotVerified */ echo $_i ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>">
          </div>
          </div>
          <?php endfor; ?>
          </div>
          </div>
          </div>

          <div class="field required">
          <label for="city" class="label"><span><?php /* @escapeNotVerified */ echo __('City') ?></span></label>
          <div class="control">
          <input type="text" name="city" value="<?php echo $block->escapeHtml($block->getFormData()->getCity()) ?>" title="<?php /* @escapeNotVerified */ echo __('City') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('city') ?>" id="city">
          </div>
          </div>

          <div class="field region required">
          <label for="region_id" class="label"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label>
          <div class="control">
          <select id="region_id" name="region_id" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="validate-select" style="display:none;">
          <option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option>
          </select>
          <input type="text" id="region" name="region" value="<?php echo $block->escapeHtml($block->getRegion()) ?>" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('region') ?>" style="display:none;">
          </div>
          </div>

          <div class="field zip required">
          <label for="zip" class="label"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label>
          <div class="control">
          <input type="text" name="postcode" value="<?php echo $block->escapeHtml($block->getFormData()->getPostcode()) ?>" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php /* @escapeNotVerified */ echo $this->helper('MagentoCustomerHelperAddress')->getAttributeValidationClass('postcode') ?>">
          </div>
          </div>

          <div class="field country required">
          <label for="country" class="label"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label>
          <div class="control">
          <?php echo $block->getCountryHtmlSelect() ?>
          </div>
          </div>
          <?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes');?>
          <?php if ($addressAttributes): ?>
          <?php $addressAttributes->setEntityType('customer_address'); ?>
          <?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
          <?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
          <?php echo $addressAttributes->setShowContainer(false)->toHtml()?>
          <?php endif;?>
          <input type="hidden" name="default_billing" value="1">
          <input type="hidden" name="default_shipping" value="1">
          </fieldset>

          <?php endif; ?>
          <fieldset class="fieldset create account" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
          <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Sign-in Information') ?></span></legend><br>
          <div class="field required">
          <label for="email_address" class="label"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
          <div class="control">
          <input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $block->escapeHtml($block->getFormData()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true">
          </div>
          </div>
          <div class="field password required" data-mage-init='"passwordStrengthIndicator": '>
          <label for="password" class="label"><span><?php /* @escapeNotVerified */ echo __('Password') ?></span></label>
          <div class="control">
          <input type="password" name="password" id="password"
          title="<?php /* @escapeNotVerified */ echo __('Password') ?>"
          class="input-text"
          data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
          data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
          data-validate="required:true, 'validate-customer-password':true"
          autocomplete="off">
          <div id="password-strength-meter-container" data-role="password-strength-meter" >
          <div id="password-strength-meter" class="password-strength-meter">
          <?php /* @escapeNotVerified */ echo __('Password Strength'); ?>:
          <span id="password-strength-meter-label" data-role="password-strength-meter-label" >
          <?php /* @escapeNotVerified */ echo __('No Password'); ?>
          </span>
          </div>
          </div>
          </div>

          </div>
          <div class="field confirmation required">
          <label for="password-confirmation" class="label"><span><?php /* @escapeNotVerified */ echo __('Confirm Password') ?></span></label>
          <div class="control">
          <input type="password" name="password_confirmation" title="<?php /* @escapeNotVerified */ echo __('Confirm Password') ?>" id="password-confirmation" class="input-text" data-validate="required:true, equalTo:'#password'" autocomplete="off">
          </div>
          </div>
          <?php echo $block->getChildHtml('form_additional_info'); ?>
          </fieldset>
          <div class="actions-toolbar">
          <div class="primary">
          <button type="submit" class="action submit primary" title="<?php /* @escapeNotVerified */ echo __('Create an Account') ?>"><span><?php /* @escapeNotVerified */ echo __('Create an Account') ?></span></button>
          </div>
          <div class="secondary">
          <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a>
          </div>
          </div>
          </form>
          <script>
          require([
          'jquery',
          'mage/mage'
          ], function($)

          var dataForm = $('#form-validate');
          var ignore = <?php /* @escapeNotVerified */ echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

          dataForm.mage('validation',
          <?php if ($_dob->isEnabled()): ?>
          errorPlacement: function(error, element)
          if (element.prop('id').search('full') !== -1)
          var dobElement = $(element).parents('.customer-dob'),
          errorClass = error.prop('class');
          error.insertAfter(element.parent());
          dobElement.find('.validate-custom').addClass(errorClass)
          .after('<div class="' + errorClass + '"></div>');

          else
          error.insertAfter(element);

          ,
          ignore: ':hidden:not(' + ignore + ')'
          <?php else: ?>
          ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
          <?php endif ?>
          ).find('input:text').attr('autocomplete', 'off');

          );
          </script>
          <?php if ($block->getShowAddressFields()): ?>
          <script type="text/x-magento-init">

          "#country":
          "regionUpdater":
          "optionalRegionAllowed": <?php /* @escapeNotVerified */ echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
          "regionListId": "#region_id",
          "regionInputId": "#region",
          "postcodeId": "#zip",
          "form": "#form-validate",
          "regionJson": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
          "defaultRegion": "<?php /* @escapeNotVerified */ echo $block->getFormData()->getRegionId() ?>",
          "countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper('MagentoDirectoryHelperData')->getCountriesWithOptionalZip(true) ?>



          </script>
          <?php endif; ?>


          Step 4: Override edit.phtml file using customer_account_edit.xml



          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <update handle="customer_account"/>
          <body>
          <!-- Set Custom Template for Register form -->
          <referenceBlock name="customer_edit">
          <action method="setTemplate">
          <argument name="template" xsi:type="string"><vendor>_<Module>::form/edit.phtml</argument>
          </action>
          </referenceBlock>
          <!-- End -->
          </body>
          </page>


          Step 5: form/edit.phtml



          <?php $_helper = $this->helper('<Vendor><Module>HelperData'); ?>
          <form class="form form-edit-account" action="<?php /* @escapeNotVerified */ echo $block->getUrl('customer/account/editPost') ?>" method="post" id="form-validate" enctype="multipart/form-data" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>" autocomplete="off">
          <fieldset class="fieldset info">
          <?php echo $block->getBlockHtml('formkey')?>
          <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Account Information') ?></span></legend><br>
          <?php echo $block->getLayout()->createBlock('MagentoCustomerBlockWidgetName')->setObject($block->getCustomer())->toHtml() ?>

          <?php $_dob = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetDob') ?>
          <?php $_taxvat = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetTaxvat') ?>
          <?php $_gender = $block->getLayout()->createBlock('MagentoCustomerBlockWidgetGender') ?>
          <?php if ($_dob->isEnabled()): ?>
          <?php echo $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
          <?php endif ?>
          <?php if ($_taxvat->isEnabled()): ?>
          <?php echo $_taxvat->setTaxvat($block->getCustomer()->getTaxvat())->toHtml() ?>
          <?php endif ?>
          <?php if ($_gender->isEnabled()): ?>
          <?php echo $_gender->setGender($block->getCustomer()->getGender())->toHtml() ?>
          <?php endif ?>

          <!-- Custom Code For Profile-Name Field -->
          <div class="field" data-container="profile-name">
          <?php $linkedinProfile = $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'profile_name')); ?>
          <label class="label" for="profile-name">
          <span>
          <?php /* @escapeNotVerified */ echo __('Profile Name') ?>
          </span>
          </label>
          <div class="control">
          <input type="text" name="profile_name" id="linkedin-profile" data-input="linkedin-profile" value="<?php echo $block->escapeHtml($_helper->getCustomerAttributeValue($this->getCustomer()->getId(), 'linkedin_profile')); ?>" title="<?php /* @escapeNotVerified */ echo __('Profile Name') ?>" class="input-file"/>
          </div>
          </div>
          <!-- End -->
          <div class="field choice">
          <input type="checkbox" name="change_email" id="change-email" data-role="change-email" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Email') ?>" class="checkbox" />
          <label class="label" for="change-email"><span><?php /* @escapeNotVerified */ echo __('Change Email') ?></span></label>
          </div>
          <div class="field choice">
          <input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" title="<?php /* @escapeNotVerified */ echo __('Change Password') ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox" />
          <label class="label" for="change-password"><span><?php /* @escapeNotVerified */ echo __('Change Password') ?></span></label>
          </div>
          </fieldset>

          <fieldset class="fieldset password" data-container="change-email-password">
          <legend class="legend"><span data-title="change-email-password"><?php echo __('Change Email and Password') ?></span></legend><br>
          <div class="field email required" data-container="change-email">
          <label class="label" for="email"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label>
          <div class="control">
          <input type="email" name="email" id="email" autocomplete="email" data-input="change-email" value="<?php echo $block->escapeHtml($block->getCustomer()->getEmail()) ?>" title="<?php echo __('Email') ?>" class="input-text" data-validate="required:true, 'validate-email':true" />
          </div>
          </div>
          <div class="field password current required">
          <label class="label" for="current-password"><span><?php echo __('Current Password') ?></span></label>
          <div class="control">
          <input type="password" class="input-text" name="current_password" id="current-password" data-input="current-password" autocomplete="off" />
          </div>
          </div>
          <div class="field new password required" data-container="new-password" data-mage-init='"passwordStrengthIndicator": '>
          <label class="label" for="password"><span><?php /* @escapeNotVerified */ echo __('New Password') ?></span></label>
          <div class="control">
          <input type="password" class="input-text" name="password" id="password"
          data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
          data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
          data-input="new-password"
          data-validate="required:true, 'validate-customer-password':true"
          autocomplete="off" />
          <div id="password-strength-meter-container" data-role="password-strength-meter" >
          <div id="password-strength-meter" class="password-strength-meter">
          <?php echo __('Password Strength'); ?>:
          <span id="password-strength-meter-label" data-role="password-strength-meter-label" >
          <?php echo __('No Password'); ?>
          </span>
          </div>
          </div>
          </div>
          </div>
          <div class="field confirm password required" data-container="confirm-password">
          <label class="label" for="password-confirmation"><span><?php echo __('Confirm New Password') ?></span></label>
          <div class="control">
          <input type="password" class="input-text" name="password_confirmation" id="password-confirmation"
          data-input="confirm-password"
          autocomplete="off" />
          </div>
          </div>
          <?php echo $block->getChildHtml('form_additional_info'); ?>
          </fieldset>
          <div class="actions-toolbar">
          <div class="primary">
          <button type="submit" class="action save primary" title="<?php echo __('Save') ?>"><span><?php echo __('Save') ?></span></button>
          </div>
          <div class="secondary">
          <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php echo __('Go back') ?></span></a>
          </div>
          </div>
          </form>
          <script>
          require([
          "jquery",
          "mage/mage"
          ], function($)
          var dataForm = $('#form-validate');
          var ignore = <?php echo $_dob->isEnabled() ? ''input[id$="full"]'' : 'null'; ?>;

          dataForm.mage('validation',
          <?php if ($_dob->isEnabled()): ?>
          errorPlacement: function(error, element)
          if (element.prop('id').search('full') !== -1)
          var dobElement = $(element).parents('.customer-dob'),
          errorClass = error.prop('class');
          error.insertAfter(element.parent());
          dobElement.find('.validate-custom').addClass(errorClass)
          .after('<div class="' + errorClass + '"></div>');

          else
          error.insertAfter(element);

          ,
          ignore: ':hidden:not(' + ignore + ')'
          <?php else: ?>
          ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
          <?php endif ?>
          );
          );
          </script>
          <script type="text/x-magento-init">

          "[data-role=change-email], [data-role=change-password]":
          "changeEmailPassword":
          "titleChangeEmail": "<?php echo __('Change Email') ?>",
          "titleChangePassword": "<?php echo __('Change Password') ?>",
          "titleChangeEmailAndPassword": "<?php echo __('Change Email and Password') ?>"



          </script>


          Step 6: helper/data.php



          <?php

          namespace <Vendor><Module>Helper;

          use MagentoFrameworkObjectManagerInterface;
          use MagentoFrameworkAppActionAction;

          class Data extends MagentoFrameworkAppHelperAbstractHelper

          protected $_customerFactory;

          protected $objectManager;

          /**
          * Initialize dependencies.
          *
          * @param MagentoFrameworkAppHelperContext $context
          * @param MagentoCustomerModelCustomerFactory $customerFactory
          */
          public function __construct(
          MagentoFrameworkAppHelperContext $context,
          MagentoCustomerModelCustomerFactory $customerFactory,
          ObjectManagerInterface $objectManager
          )
          $this->_customerFactory = $customerFactory;
          $this->objectManager = $objectManager;
          parent::__construct($context);


          /**
          * @inheritdoc
          */
          public function getCustomerAttributeValue($customerId, $attributeCode)

          $customerObject = $this->_customerFactory->create()->load($customerId);
          return $attribute = ($customerObject->getData($attributeCode)) ? $customerObject->getData($attributeCode): false;




          Done!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 18 at 13:38









          Rk RathodRk Rathod

          2,4163 silver badges17 bronze badges




          2,4163 silver badges17 bronze badges























              0














              It looks for me that you would like to add a new customer dropdown attribute, not a custom dropdown attribute, that's a huge difference,



              Below I described how to add a new dropdown attribute to customer and display it on Registration & Customer Edit page



              To achieve that you need to create an in InstallData.php (or Upgrade.php depending on situation) file where you will place your code.



              Assuming it is InstallData.php



              use MagentoCustomerModelCustomer;
              use MagentoCustomerSetupCustomerSetupFactory;
              use MagentoFrameworkSetupModuleContextInterface;
              use MagentoFrameworkSetupModuleDataSetupInterface;

              /**
              * @param ModuleDataSetupInterface $setup
              * @param ModuleContextInterface $context
              */
              class InstallData implements InstallDataInterface
              {
              /**
              * @var CustomerSetupFactory
              */
              private $customerSetupFactory;

              /**
              * InstallData constructor.
              * @param CustomerSetupFactory $customerSetupFactory
              */
              public function __construct(
              CustomerSetupFactory $customerSetupFactory
              )
              $this->customerSetupFactory = $customerSetupFactory;


              /**
              * @param ModuleDataSetupInterface $setup
              * @param ModuleContextInterface $context
              */
              public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

              $setup->startSetup();
              $this->createUserAttribute($setup);
              $setup->endSetup();

              /**
              * @param ModuleDataSetupInterface $setup
              */
              private function createUserAttribute(ModuleDataSetupInterface $setup)

              $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
              $customerSetup->addAttribute(
              Customer::ENTITY,
              "account_group",
              [
              'type' => 'int',
              'label' => 'Account Group',
              'input' => 'select',
              'source' => 'MagentoEavModelEntityAttributeSourceTable',
              'required' => true,
              'sort_order' => 215,
              'visible' => true,
              'position' => 215,
              'admin_checkout' => 1,
              'option' => ['values' => ['Group_1', 'Group_2']],
              'user_defined' => true,
              'visible_on_front' => true,
              'system' => 0,
              ]
              );

              $customerSetup->getEavConfig()
              ->getAttribute(Customer::ENTITY, "account_group")
              ->addData([
              'used_in_forms' =>
              ['adminhtml_customer', 'customer_account_edit', 'customer_account_create']
              ])
              ->save();



              As you can see last part: $customerSetup->getEavConfig()
              Is responsible for setting correct forms where do you want to show them to user.



              After run:
              php bin/magento setup:upgrade






              share|improve this answer





























                0














                It looks for me that you would like to add a new customer dropdown attribute, not a custom dropdown attribute, that's a huge difference,



                Below I described how to add a new dropdown attribute to customer and display it on Registration & Customer Edit page



                To achieve that you need to create an in InstallData.php (or Upgrade.php depending on situation) file where you will place your code.



                Assuming it is InstallData.php



                use MagentoCustomerModelCustomer;
                use MagentoCustomerSetupCustomerSetupFactory;
                use MagentoFrameworkSetupModuleContextInterface;
                use MagentoFrameworkSetupModuleDataSetupInterface;

                /**
                * @param ModuleDataSetupInterface $setup
                * @param ModuleContextInterface $context
                */
                class InstallData implements InstallDataInterface
                {
                /**
                * @var CustomerSetupFactory
                */
                private $customerSetupFactory;

                /**
                * InstallData constructor.
                * @param CustomerSetupFactory $customerSetupFactory
                */
                public function __construct(
                CustomerSetupFactory $customerSetupFactory
                )
                $this->customerSetupFactory = $customerSetupFactory;


                /**
                * @param ModuleDataSetupInterface $setup
                * @param ModuleContextInterface $context
                */
                public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

                $setup->startSetup();
                $this->createUserAttribute($setup);
                $setup->endSetup();

                /**
                * @param ModuleDataSetupInterface $setup
                */
                private function createUserAttribute(ModuleDataSetupInterface $setup)

                $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
                $customerSetup->addAttribute(
                Customer::ENTITY,
                "account_group",
                [
                'type' => 'int',
                'label' => 'Account Group',
                'input' => 'select',
                'source' => 'MagentoEavModelEntityAttributeSourceTable',
                'required' => true,
                'sort_order' => 215,
                'visible' => true,
                'position' => 215,
                'admin_checkout' => 1,
                'option' => ['values' => ['Group_1', 'Group_2']],
                'user_defined' => true,
                'visible_on_front' => true,
                'system' => 0,
                ]
                );

                $customerSetup->getEavConfig()
                ->getAttribute(Customer::ENTITY, "account_group")
                ->addData([
                'used_in_forms' =>
                ['adminhtml_customer', 'customer_account_edit', 'customer_account_create']
                ])
                ->save();



                As you can see last part: $customerSetup->getEavConfig()
                Is responsible for setting correct forms where do you want to show them to user.



                After run:
                php bin/magento setup:upgrade






                share|improve this answer



























                  0












                  0








                  0







                  It looks for me that you would like to add a new customer dropdown attribute, not a custom dropdown attribute, that's a huge difference,



                  Below I described how to add a new dropdown attribute to customer and display it on Registration & Customer Edit page



                  To achieve that you need to create an in InstallData.php (or Upgrade.php depending on situation) file where you will place your code.



                  Assuming it is InstallData.php



                  use MagentoCustomerModelCustomer;
                  use MagentoCustomerSetupCustomerSetupFactory;
                  use MagentoFrameworkSetupModuleContextInterface;
                  use MagentoFrameworkSetupModuleDataSetupInterface;

                  /**
                  * @param ModuleDataSetupInterface $setup
                  * @param ModuleContextInterface $context
                  */
                  class InstallData implements InstallDataInterface
                  {
                  /**
                  * @var CustomerSetupFactory
                  */
                  private $customerSetupFactory;

                  /**
                  * InstallData constructor.
                  * @param CustomerSetupFactory $customerSetupFactory
                  */
                  public function __construct(
                  CustomerSetupFactory $customerSetupFactory
                  )
                  $this->customerSetupFactory = $customerSetupFactory;


                  /**
                  * @param ModuleDataSetupInterface $setup
                  * @param ModuleContextInterface $context
                  */
                  public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

                  $setup->startSetup();
                  $this->createUserAttribute($setup);
                  $setup->endSetup();

                  /**
                  * @param ModuleDataSetupInterface $setup
                  */
                  private function createUserAttribute(ModuleDataSetupInterface $setup)

                  $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
                  $customerSetup->addAttribute(
                  Customer::ENTITY,
                  "account_group",
                  [
                  'type' => 'int',
                  'label' => 'Account Group',
                  'input' => 'select',
                  'source' => 'MagentoEavModelEntityAttributeSourceTable',
                  'required' => true,
                  'sort_order' => 215,
                  'visible' => true,
                  'position' => 215,
                  'admin_checkout' => 1,
                  'option' => ['values' => ['Group_1', 'Group_2']],
                  'user_defined' => true,
                  'visible_on_front' => true,
                  'system' => 0,
                  ]
                  );

                  $customerSetup->getEavConfig()
                  ->getAttribute(Customer::ENTITY, "account_group")
                  ->addData([
                  'used_in_forms' =>
                  ['adminhtml_customer', 'customer_account_edit', 'customer_account_create']
                  ])
                  ->save();



                  As you can see last part: $customerSetup->getEavConfig()
                  Is responsible for setting correct forms where do you want to show them to user.



                  After run:
                  php bin/magento setup:upgrade






                  share|improve this answer















                  It looks for me that you would like to add a new customer dropdown attribute, not a custom dropdown attribute, that's a huge difference,



                  Below I described how to add a new dropdown attribute to customer and display it on Registration & Customer Edit page



                  To achieve that you need to create an in InstallData.php (or Upgrade.php depending on situation) file where you will place your code.



                  Assuming it is InstallData.php



                  use MagentoCustomerModelCustomer;
                  use MagentoCustomerSetupCustomerSetupFactory;
                  use MagentoFrameworkSetupModuleContextInterface;
                  use MagentoFrameworkSetupModuleDataSetupInterface;

                  /**
                  * @param ModuleDataSetupInterface $setup
                  * @param ModuleContextInterface $context
                  */
                  class InstallData implements InstallDataInterface
                  {
                  /**
                  * @var CustomerSetupFactory
                  */
                  private $customerSetupFactory;

                  /**
                  * InstallData constructor.
                  * @param CustomerSetupFactory $customerSetupFactory
                  */
                  public function __construct(
                  CustomerSetupFactory $customerSetupFactory
                  )
                  $this->customerSetupFactory = $customerSetupFactory;


                  /**
                  * @param ModuleDataSetupInterface $setup
                  * @param ModuleContextInterface $context
                  */
                  public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

                  $setup->startSetup();
                  $this->createUserAttribute($setup);
                  $setup->endSetup();

                  /**
                  * @param ModuleDataSetupInterface $setup
                  */
                  private function createUserAttribute(ModuleDataSetupInterface $setup)

                  $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
                  $customerSetup->addAttribute(
                  Customer::ENTITY,
                  "account_group",
                  [
                  'type' => 'int',
                  'label' => 'Account Group',
                  'input' => 'select',
                  'source' => 'MagentoEavModelEntityAttributeSourceTable',
                  'required' => true,
                  'sort_order' => 215,
                  'visible' => true,
                  'position' => 215,
                  'admin_checkout' => 1,
                  'option' => ['values' => ['Group_1', 'Group_2']],
                  'user_defined' => true,
                  'visible_on_front' => true,
                  'system' => 0,
                  ]
                  );

                  $customerSetup->getEavConfig()
                  ->getAttribute(Customer::ENTITY, "account_group")
                  ->addData([
                  'used_in_forms' =>
                  ['adminhtml_customer', 'customer_account_edit', 'customer_account_create']
                  ])
                  ->save();



                  As you can see last part: $customerSetup->getEavConfig()
                  Is responsible for setting correct forms where do you want to show them to user.



                  After run:
                  php bin/magento setup:upgrade







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 18 at 16:36

























                  answered Jun 18 at 16:30









                  Gosu PrzmakGosu Przmak

                  185 bronze badges




                  185 bronze badges



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Magento Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f278744%2fmagento2-how-can-i-add-custom-drop-down-field-in-registration-form%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                      Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                      Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form