I am adding customer attribute in magento 2
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'test', [
'type' => 'varchar',
'label' => 'Test',
'input' => 'text',
'required' => true,
'visible' => true,
'user_defined' => true,
'sort_order' => 90,
'position' => 90,
'system' => 0,
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'test')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['adminhtml_customer','customer_account_create'],
]);
$attribute->save();
add in register.phtml
<div class="field test">
<label for="test" class="label"><span><?php /* @escapeNotVerified */ echo __('Test') ?></span></label>
<div class="control">
<input type="text" name="test" id="test" value="<?php echo $block->escapeHtml($block->getFormData()->getTest()) ?>" title="<?php /* @escapeNotVerified */ echo __('Test') ?>" class="input-text">
</div>
</div>
and now when i add values in form for register it gives me an error
"Test" is a required value
What to do? i can't understand