0

I want to add the Newsletter checkbox into the Magento2 Customer Login form, when the user clicks the submit button the form validated the email and password, and the newsletter checkbox's state (only if checked) saves into a database under "CUSTOMER INFORMATION -> Newsletter".

How do I do that? Please help. Thank you in advance.

1 Answer 1

0

Add checkbox in registration form is a valid thing but in login page is I don't think it's a good way. You can add this in registration form as below

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

<?php if ($block->isNewsletterEnabled()): ?>
    <div class="field choice newsletter">
        <input type="checkbox" name="is_subscribed" title="<?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
        <label for="is_subscribed" class="label"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Newsletter') ?></span></label>
    </div>
    <?php /* Extensions placeholder */ ?>
    <?php echo $block->getChildHtml('customer.form.register.newsletter')?>
<?php endif ?>
1
  • Hi Gohil! Thank you for quick answer... The newsletter checkbox is default implemented in register.phtml. My Boss want me to add a newsletter checkbox into the login form, but I'm newbie in Magento, that's why I need help for implementation.
    – iivo
    Nov 2, 2021 at 8:40

Your Answer

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

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