In magento 2.3, I have created custom field(GST number) on registration form. This field's value is saving on DB as. This field's value is showing/editing on admin panel(customer edit). But not showing in customer's account information tab. As i try to update first or last name and click on save button then hey show validation message:
GST number is required value
.
There is my script:
<?php
namespace Test\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, "gst_number");
$attributeSetId = $eavSetup->getDefaultAttributeSetId(Customer::ENTITY);
$attributeGroupId = $eavSetup->getDefaultAttributeGroupId(Customer::ENTITY);
$eavSetup->addAttribute(Customer::ENTITY, 'gst_number', [
// Attribute parameters
'type' => 'varchar',
'label' => 'GST number',
'input' => 'text',
'required' => true,
'visible' => true,
'user_defined' => true,
'sort_order' => 990,
'position' => 990,
'system' => 0,
]);
$attribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'gst_number');
$attribute->setData('attribute_set_id', $attributeSetId);
$attribute->setData('attribute_group_id', $attributeGroupId);
$attribute->setData('used_in_forms', [
'adminhtml_customer',
'customer_account_create',
'customer_account_edit'
]);
$this->attributeResource->save($attribute);
}
}
?>