app/code/Cm/Customer/Setup/InstallData.php
<?php
namespace Cm\Customer\Setup;
use Magento\Customer\Model\Customer;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements \Magento\Framework\Setup\InstallDataInterface
{
private $eavSetupFactory;
private $eavConfig;
private $attributeResource;
public function __construct(
\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory,
\Magento\Eav\Model\Config $eavConfig,
\Magento\Customer\Model\ResourceModel\Attribute $attributeResource
) {
$this->eavSetupFactory = $eavSetupFactory;
$this->eavConfig = $eavConfig;
$this->attributeResource = $attributeResource;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->removeAttribute(Customer::ENTITY, "skype");
$attributeSetId = $eavSetup->getDefaultAttributeSetId(Customer::ENTITY);
$attributeGroupId = $eavSetup->getDefaultAttributeGroupId(Customer::ENTITY);
$eavSetup->addAttribute(Customer::ENTITY, 'skype', [
// Attribute parameters
'type' => 'varchar',
'label' => 'Skype Account',
'input' => 'text',
'required' => true,
'visible' => true,
'user_defined' => true,
'sort_order' => 990,
'position' => 990,
'system' => 0,
]);
$attribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'skype');
$attribute->setData('attribute_set_id', $attributeSetId);
$attribute->setData('attribute_group_id', $attributeGroupId);
/*
//You can use this attribute in the following forms
adminhtml_checkout
adminhtml_customer
adminhtml_customer_address
customer_account_create
customer_account_edit
customer_address_edit
customer_register_address
*/
$attribute->setData('used_in_forms', [
'adminhtml_customer',
'customer_account_create',
'customer_account_edit'
]);
$this->attributeResource->save($attribute);
}
}
?>
app/code/Cm/Customer/view/frontend/templates/additional.phtml
<div class="field skype required">
<label class="label" for="skype">
<span><?= $block->escapeHtml(__('Skype Account')) ?></span>
</label>
<div class="control">
<input type="text" name="skype" id="skype" value="" title="<?= $block->escapeHtmlAttr(__('Skype Account')) ?>" class="input-text" data-validate="{required:true}">
</div>
</div>
app/code/Cm/Customer/view/frontend/layout/customer_account_create.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="form.additional.info">
<block class="Magento\Framework\View\Element\Template" name="form_additional_info_customer" template="Rsgitech_Customer::additional.phtml"/>
</referenceContainer>
</body>
</page>
you want to add a custom field as static refer this lik
otherwise you want to add custom field as dynamic field use this extension