2

I want to show Address fields in Registration form of Magento 2.4.0

I have created file in my theme as below.

app/design/frontend/YOUR_PACKAGE/YOUR_THEME/Magento_Customer/layout/customer_account_create.xml

I have set the action method called setShowAddressFields like true by adding below code.

<?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">
 <action method="setShowAddressFields">
 <argument name="show.address.fields" xsi:type="boolean">true</argument>
 </action>
 </referenceBlock>
 </body>
</page>

I can see address fields after adding this in the layout file, but I could not see state drop-down. I have attached a screenshot of registration form.

enter image description here

asked Sep 30, 2020 at 11:24

2 Answers 2

2

Create a copy of

/vendor/magento/module-customer/view/frontend/templates/form/register.phtml

on your template:

/app/design/frontend/<vendor_name>/<template_name>/Magento_Customer/templates/form/register.phtml

And replace lines 338-340

"regionJson": {$regionJson},
"defaultRegion": "{$regionId}",
"countriesWithOptionalZip": {$countriesWithOptionalZip}

with these

"regionJson": <?= /* @noEscape */ $regionJson ?>,
"defaultRegion": "<?= /* @noEscape */ $regionId ?>",
"countriesWithOptionalZip": <?= /* @noEscape */ $countriesWithOptionalZip ?>

flush cache.

answered Jan 24, 2021 at 20:29
1

The state dropdown looks broken in register.phtml. Create a module, or override it in your theme.

Line 328, change it to echo the variables:

<script type="text/x-magento-init">
{
 "#country": {
 "regionUpdater": {
 "optionalRegionAllowed": <?= /* @noEscape */ $displayAll ? 'true' : 'false' ?>,
 "regionListId": "#region_id",
 "regionInputId": "#region",
 "postcodeId": "#zip",
 "form": "#form-validate",
 "regionJson": <?= $regionJson ?>,
 "defaultRegion": <?= $regionId ?>,
 "countriesWithOptionalZip": <?= $countriesWithOptionalZip ?>
 }
 }
}
answered Jan 15, 2021 at 21:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.