Magento 2 – Adding Required Unchecked Checkbox for Terms and Conditions on New Account Registration

gdprmagento2registerregistrationterms and conditions

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.

Best Answer

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>
Related Topic