I’m truly newbie to Magento 2 developer, and I’m currently facing a problem that I can’t amazing how to solve the problem that describes as below:
The problem:
I’ve added a checkbox (Tilmeld nyhedsbrev) in English (Sign Up for Newsletter) into the Porto Theme’s login form. Please take a look at the attachment image for further information.
The question is:
If a customer marked the checkbox (checked=true) the click the LOG IND (submit button) button, well, then… how do I save the customer’s email into Magento 2 Customer newsletter module database?
Here is the code for that action:
escapeHtml(__(‘Registered Customers’)) ?>
escapeUrl($block->getPostActionUrl()) ?>”
method=”post”
id=”login-form”
data-mage-init='{“validation”:{}}’>
[![enter image description here][1]][1]getBlockHtml(‘formkey’) ?>
escapeHtml(__(‘* Required Fields’)) ?>”>
escapeHtml(__(‘If you have an account, sign in with your email address.’)) ?>
<div class="field email required">
<label class="label" for="email"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input name="login[username]" value="<?= $block->escapeHtmlAttr($block->getUsername()) ?>" <?php if ($block->isAutocompleteDisabled()) : ?> autocomplete="off"<?php endif; ?> id="email" type="email" class="input-text line-height-xl" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" data-mage-init='{"mage/trim-input":{}}' data-validate="{required:true, 'validate-email':true}">
</div>
</div>
<div class="field password required">
<label for="pass" class="label"><span><?= $block->escapeHtml(__('Password')) ?></span></label>
<div class="control">
<input name="login[password]" type="password" <?php if ($block->isAutocompleteDisabled()) : ?> autocomplete="off"<?php endif; ?> class="input-text line-height-xl" id="pass" title="<?= $block->escapeHtmlAttr(__('Password')) ?>" data-validate="{required:true}">
</div>
</div>
<?= $block->getChildHtml('form_additional_info') ?>
<div class="field">
<a class="action remind" href="<?= $block->escapeUrl($block->getForgotPasswordUrl()) ?>"><span><?= $block->escapeHtml(__('Forgot Your Password?')) ?></span></a>
</div>
<div class="actions-toolbar">
<div class="primary"><button type="submit" class="action login primary btn-v-dark py-3 text-md w-100" name="send" id="send2"><span><?= $block->escapeHtml(__('Sign In')) ?></span></button></div>
<div class="secondary">
<a href="/customer/account/create/" class="action create primary btn-v-dark py-3 text-md w-100"><span><?= $block->escapeHtml(__('Create an Account')) ?></span></a>
</div>
<style>
.customer-account-login .action.create {
display: none;
}
</style>
</div>
<div class="field choice login-newsletter">
<input
type="checkbox"
name="is_subscribed"
id="login-newsletter"
value="1"
title="<?= $block->escapeHtmlAttr(__('Sign Up for Newsletter')) ?>"
<?php /* default unchecked */?>
class="checkbox">
<label for="login-newsletter" class="label"><span><?= $block->escapeHtml(__('Sign Up for Newsletter')) ?></span></label>
</div>
</fieldset>
</form>
</div>