How to Show Address Fields in Registration Form in Magento 2
Online store owners tend to collect maximum customer information which can be used for marketing purposes and improve the customer experience.
Registration form is best for collecting maximum data which can be used further for business requirements.
The default Magento 2 registration form allows admin to collect customer data such as:
- Name and last name
- date of birth
- middle name
- Telephone
- Fax
Note, In Magento 2, the Show or we can say Enable Middle Name in Registration Form is an optional field, also you can add date of birth in registration form as an customer attribute.
However, it may not be enough for every business with various requirements.
One important detail about the customer is their address. A store owner can show address fields in registration form in Magento 2 to collect the location details and use it in designing the marketing strategy.
In addition to collecting address details, it is crucial for store owners to show Tax/VAT Number in Registration Form in Magento 2 as it helps in complying with tax regulations and building trust with customers by displaying transparency in pricing.
For instance, if your store is selling apparels, it’s a waste of time to send notification of winter clothes(Jackets, scarf, gloves) to the customers living in a hot climate!
Also, the address detail is essential if your business is delivering physical products.
Use the below solution to display address fields in the Magento 2 sign up form.
The registration form in the default Magento 2 looks something like this:
Now, we’ll see how to add the address fields in this form.
Method to Show Address Fields in Registration Form in Magento 2
Add below code in your customer_account_create.xml file
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="customer_form_register"> <arguments> <argument name="show_address_fields" xsi:type="boolean">true</argument> </arguments> </referenceBlock> </body> </page> |
After applying the solution, the custom sign up form displays the address field as shown here:
That’s it! Also to prevent yourself from multiple form submission and storing same data of same user, once clicked on submit button Magento 2 disable submit button on form submission.
Do you have any doubts? Mention them in the Comments section below. You can also add or remove address field from PDF in Magento 2 as per your requirements.
I’d be glad to help you.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
4 Comments
Hi Team,
How to show address section after sign in information means at last of the sign up page?
Thanks
Hello Sanjeev,
You need to override the phtml file into your theme and change the code in that file,
In order to find out which file is getting called there, you can use the below link:
https://meetanshi.com/blog/enable-template-path-hints-in-magento-2/
Thank You
How to only show the Phone field in partifcular and not the other fields
Hello,
I am sorry but it is not possible. All the address field will be displayed.
Thank you.