Today, we are going to guide you on how to add custom field in the
Magento2 registration form. In our last blog, we discussed how to save custom attribute value after customer register in magento2.
Let see how to add custom field in the Magento2 registration form step by step:-
Step-1 Create additional.phtml file
Create view file additional.phtml at
1 |
app/code/Webiators/CustomerAttribute/view/frontend/templates/additional.phtml |
to show field on customer registration form.
1 2 3 4 5 6 7 8 |
<div class="field magento_username required"> <label class="label" for="magento_username"> <span><?= $block->escapeHtml(__('Magento Username')) ?></span> </label> <div class="control"> <input type="text" name="magento_username" id="magento_username" value="" title="<?= $block->escapeHtmlAttr(__('Magento Username')) ?>" class="input-text" data-validate="{required:true}"> </div> </div> |
Step-2 Create customer_account_create.xml file
Create layout file customer_account_create.xml
1 |
app/code/Webiators/CustomerAttribute/view/frontend/layout/customer_account_create.xml |
1 2 3 4 5 6 7 8 9 |
<?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="Webiators_CustomerAttribute::additional.phtml"/> </referenceContainer> </body> </page> |
Let me know if you have any questions or faced any issue while following this method for add custom field in the Magento2 registration form in the Comments section below.
Thank you.