I will attached the phtml and php block code but client side mail does
not send?
subscribe.phtml
<div class="block newsletter">
<div class="title"><strong>Newsletter</strong></div>
<div class="content">
<form class="form subscribe"
novalidate
action="<?php /* @escapeNotVerified */ echo $block->getFormActionUrl() ?>"
method="post"
data-mage-init='{"validation": {"errorClass": "mage-error"}}'
id="newsletter-validate-detail">
<div class="field newsletter">
<label class="label" for="newsletter"><span><?php /* @escapeNotVerified */ echo __('Sign Up for Our Newsletter:') ?></span></label>
<div class="control">
<input name="email" type="email" id="newsletter"
placeholder="<?php /* @escapeNotVerified */ echo __('Enter your email address') ?>"
data-validate="{required:true, 'validate-email':true}"/>
</div>
</div>
<div class="actions">
<button class="action subscribe primary" title="<?php /* @escapeNotVerified */ echo __('Subscribe') ?>" type="submit">
<span><?php /* @escapeNotVerified */ echo __('Subscribe') ?></span>
</button>
</div>
</form>
</div>
</div>
Subscribe.php
<?php
namespace Magento\Newsletter\Block;
class Subscribe extends \Magento\Framework\View\Element\Template
{
/**
* Retrieve form action url and set "secure" param to avoid confirm
* message when we submit form from secure page to unsecure
*
* @return string
*/
public function getFormActionUrl()
{
$checkSubscriber = $this->_subscriber->loadByEmail($email);
if ($checkSubscriber->isSubscribed()) {
$response = [
'status' => 'ERROR',
'msg' => __('Something went wrong with the subscription.'),
];
}
return $this->getUrl('newsletter/subscriber/new', ['_secure' => true]);
}
}
?>
Please help this task ???
Best Answer
it is simply your logic issue,
$checkSubscriber = $this->_subscriber->loadByEmail($email);
Where you getting
$email
.Also,
Is not right. Because of form action is
newsletter/subscriber/new
and HOW will get the response from this URL to the current page?