0

enter image description here

I want Checkbox required field

I agree to the Terms and Conditions.

I am using this code but it's not working.

  • Have you added terms and conditions on the checkout page? – user_61205 Aug 30 '18 at 12:39
  • i want in registration page – kiran Aug 30 '18 at 15:02
  • Okay, I will give one code You can add. – user_61205 Aug 31 '18 at 4:46
0

==>Overide Layout Your own module This file customer_account_create.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="form.additional.info">
            <block class="Vendor\Module\Block\Form\Optin" name="gdpr.account.addoptin"
                template="Vendor_Module::account/optin.phtml" before="-" />
        </referenceContainer>
    </body>
</page>

==> After Layout Made You Made Optin.php Block your own Module

<?php

namespace Vendor\Module\Block\Form;

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

class Optin extends \Magento\Framework\View\Element\Template
{
    /**
     *
     * @var bool
     */
    protected $personnalizedSuggestions = false;

    /**
     *
     * @var bool
     */
    protected $thirdParty = false;

    /**
     *
     * @var Data
     */
    protected $helper;

    /**
     *
     * @param Context $context
     * @param array $data
     * @param
     */
    public function __construct(
        Context $context,
        array $data = [],
        \Magento\Customer\Model\Session $customerSession,
        CustomerRepositoryInterface $customerRepository
    ) {
        $this->customerSession = $customerSession;
        $this->customerRepository = $customerRepository;
        parent::__construct($context, $data);
    }

    public function getTermsConditionUrl()
    {
        $store_code = $this->_storeManager->getStore()->getCode();
        ==> Specify your store code 
        if ($store_code == 'en') {
        ==> Specify your store wise URL 
            $termsConditionUrl = "terms-and-conditions";
        }
        return $termsConditionUrl;
    }

    public function getPrivacyCookiesUrl()
    {
        $store_code = $this->_storeManager->getStore()->getCode();
        ==> Specify your store code 
        if ($store_code == 'en') {
        ==> Specify your store wise URL 
            $privacyCookiesUrl = "privacy-policy-cookie-restriction-mode_en";
        }
        return $privacyCookiesUrl;
    }

}

==>After Made Optin block Made optin.phtml file your own module.

<div id="gdpr-personnalized-suggestions-box" class="field choice gdpr required">
        <input type="checkbox" name="personnalized_suggestions" class="checkbox" id="account-form-personnalized-suggestions" class="input-text " data-validate="{required:true}" value="1" title="<?php /* @escapeNotVerified */ echo __('Accept user personnalization') ?>" checked="checked" />
        <label for="account-form-personnalized-suggestions" class="label"><span><?php /* @escapeNotVerified */ echo __('I agree to the terms and conditions') ?></span></label>
        <span class="tooltip wrapper">
            <a class="link tooltip toggle" href="<?php echo $block->geturl($block->getTermsConditionUrl());?>" target="_blank"><?php /* @escapeNotVerified */ echo __('What\'s this?') ?></a>
            <span class="tooltip content">
                <?php echo /* @escapeNotVerified */ __('Check this to access personnalized search result and suggestions based on your own history.')?>
            </span>
        </span>
    </div>


<div id="gdpr-third-party-box" class="field choice gdpr required">
        <input type="checkbox" name="third_party" class="checkbox" id="account-form-third-party" data-validate="{required:true}" value="1" title="<?php /* @escapeNotVerified */ echo __('Accept third party transmission') ?>" checked="checked" />
        <label for="account-form-third-party" class="label"><span><?php /* @escapeNotVerified */ echo __('I agree with the processing of personal data') ?></span></label>
        <span class="tooltip wrapper">
            <a class="link tooltip toggle" href="<?php echo $block->geturl($block->getPrivacyCookiesUrl());?>" target="_blank"><?php /* @escapeNotVerified */ echo __('What\'s this?') ?></a>
            <span class="tooltip content">
                <?php echo /* @escapeNotVerified */ __('Check this to accept third party transmission.')?>
            </span>
        </span>
    </div>

After Made optin.phtml check it.

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.