enter image description here

I have added the checkbox to my sign-up page. but I want that every user should check the button to create an account. I have tried to make it with Javascript. I am using Magento 2.3.0 Here is the code.

<div style="padding-top: 10px;">
    <input type="checkbox" required id="checkBoxRequired">
        <a href="#">Privacy & Policy</a>
    <span id="span"></span>

function validateForm() {
    var checkbox = document.getElementById("checkBoxRequired");
    if (checkbox.checked == false) {
        document.getElementById("span").innerHTML = "*Checking the checkbox";
        document.getElementById("span").style.color = "red";
        document.getElementById("span").style.display = "block";
        return false;

I have added onsubmit="return validateForm()" inside begining form tag!

1 Answer 1


you just need to overwrite register.phtml file in your theme


and add the code below after confirmarion password field

<div class="field choice privacy_policy">
    <input type="checkbox" name="privacy_policy" title="<?= $block->escapeHtmlAttr(__('Privacy & Policy')) ?>" value="1" id="privacy_policy"<?php if ($block->getFormData()->getPrivacyPolicy()) : ?> checked="checked"<?php endif; ?> class="checkbox" data-validate="{required:true}">
    <label for="privacy_policy" class="label"><span><?= $block->escapeHtml(__('Privacy & Policy')) ?></span></label>

enter image description here You don't need to add any custom JavaScript validation

Hope this will help you!

  • The classes you added, is that mandatory or I can add as I want. Commented Nov 12, 2019 at 6:25

Your Answer

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

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