2

I'm trying to add a Checkbox to account registration for terms and conditions mainly due to GDPR.

I've looked at this question: magento 2 - Terms and conditions checkbox on register page

But the answer is fairly vague. Where in the register.phtml document must they go? I've tried several locations and it causes the register form to disappear or miss elements.

The checkbox needs to be a requirement for registration but must not already be checked.

I hope someone can help me.

6

Try following way:

Step 1: VendorName/ModuleName/view/frontend/layout/customer_account_create.xml


<?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="tc" template="VendorName_ModuleName::tc.phtml"/>
        </referenceContainer>
    </body>
</page>

Step 2: VendorName/ModuleName/view/frontend/templates/tc.phtml


<div class="field tcagreecreateaccount required">
    <div class="control">
        <input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:true}" class="input-checkbox checkbox required" value="1">
        <label for="tcagreecreateaccount" class="label">
            <?= __('Custom T&C') ?>
        </label>
    </div>
</div>
2
  • required validation not working
    – mansi
    Dec 18 '18 at 10:20
  • validation working as well May 16 '21 at 17:43
2

The accepted answer works, but only makes sense if you want to really create your own code.

If you want to use magento native agreements that are also used in checkout, do the following:

Vendor_theme lives here: app/design/frontend/

Vendor_theme/Magento_Customer/layout/customer_account_create.xml

<?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\CheckoutAgreements\Block\Agreements" name="register.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/>
        </referenceContainer>
    </body>
</page>

this way the checkout agreements get used for the customer register.

2
  • 1
    This code works. Can we show other therms in checkout page and on register in-depended. Whatever the admin settings are? I mean i have two terms one for register and second for checkout ? Apr 26 '21 at 6:30
  • @user2217288 I suppose one way would be to replace the template reference of the agreements block with your own, just copy the one mentioned and modify the parts you need to change.
    – siux
    Dec 8 '21 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.