1/ You need to create a mobilePhone attribute
app/code/Vendor/Module/Setup/InstallData.php
<?php
namespace Vendor\Module\Setup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Customer\Model\Customer;
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* Install data
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* CustomerSetupFactory
* @var CustomerSetupFactory
*/
protected $customerSetupFactory;
/**
* $attributeSetFactory
* @var AttributeSetFactory
*/
private $attributeSetFactory;
/**
* initiate object
* @param CustomerSetupFactory $customerSetupFactory
* @param AttributeSetFactory $attributeSetFactory
*/
public function __construct(
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory
)
{
$this->customerSetupFactory = $customerSetupFactory;
$this->attributeSetFactory = $attributeSetFactory;
}
/**
* install data method
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var CustomerSetup $customerSetup */
$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(Customer::ENTITY, 'mobile_phone', [
'type' => 'varchar',
'label' => 'Mobile phone',
'input' => 'text',
'required' => true,
'visible' => true,
'user_defined' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
]);
//add attribute to attribute set
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mobile_phone')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
/*use this mobile phone attribute in the all bellow forms*/
'used_in_forms' => ['adminhtml_customer', 'customer_account_create', 'customer_account_edit', 'adminhtml_checkout', 'checkout_register'],
]);
$attribute->save();
}
}
2/
app/design/frontend/{Vendor}/{themename}/Magento_Customer/templates/form/register.phtml
Then add your custom attribute as something like this:
<div class="field phone required">
<label for="telephone" class="label"><span><?= $block->escapeHtml(__('Mobile')) ?></span></label>
<div class="control">
<input type="telephone" name="mobile_phone" id="mobile_phone" value="<?= $block->escapeHtmlAttr($block->getFormData()->getMobilePhone()) ?>" title="<?= $block->escapeHtmlAttr(__('Mobile Phone')) ?>" class="input-text" data-validate="{required:true, 'validate-mobilePhoneNumber':true}">
</div>
</div>