We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    The newsletter subscription module in Magento has only one field (email) by default. If you want to add  an extra field to the form (like the name), perform the following steps:

    Magemonkeys/Newsletter/registration.php

    <?php
    MagentoFrameworkComponentComponentRegistrar::register(
    	MagentoFrameworkComponentComponentRegistrar::MODULE,
    	'Magemonkeys_Newsletter',
    	__DIR__
    );
    

    Magemonkeys/Newsletter/etc/module.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Magemonkeys_Newsletter" setup_version="1.0.0"/>
        <sequence>
          <module name="Magento_Newsletter" />
        </sequence>
    </config>
    

    Magemonkeys/Newsletter/Setup/InstallSchema.php

    <?php
    
    namespace MagemonkeysNewsletterSetup;
    
    use MagentoFrameworkDBDdlTable;
    use MagentoFrameworkSetupInstallSchemaInterface;
    use MagentoFrameworkSetupModuleContextInterface;
    use MagentoFrameworkSetupSchemaSetupInterface;
    
    class InstallSchema implements InstallSchemaInterface {
    	public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) {
    		$setup->startSetup();
    
    		$table = $setup->getTable('newsletter_subscriber');
    
    		$setup->getConnection()->addColumn(
    			$table,
    			'full_name',
    			[
    				'type' => Table::TYPE_TEXT,
    				'nullable' => true,
    				'comment' => 'Name',
    			]
    		);
    
    		$setup->endSetup();
    	}
    }

    Magemonkeys/Newsletter/etc/di.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
      <preference for="MagentoNewsletterControllerSubscriberNewAction" type="MagemonkeysNewsletterControllerSubscriberNewAction" />
    </config>
    

    Magemonkeys/Newsletter/Controller/Subscriber/NewAction.php

    <?php
    
    namespace MagemonkeysNewsletterControllerSubscriber;
    
    use MagentoCustomerApiAccountManagementInterface as CustomerAccountManagement;
    use MagentoCustomerModelSession;
    use MagentoCustomerModelUrl as CustomerUrl;
    use MagentoFrameworkAppActionContext;
    use MagentoFrameworkControllerResultFactory;
    use MagentoFrameworkControllerResultRedirect;
    use MagentoFrameworkExceptionLocalizedException;
    use MagentoFrameworkPhrase;
    use MagentoNewsletterControllerSubscriberNewAction as SubscriberNewController;
    use MagentoNewsletterModelSubscriber;
    use MagentoNewsletterModelSubscriberFactory;
    use MagentoNewsletterModelSubscriptionManagerInterface;
    use MagentoStoreModelStoreManagerInterface;
    
    /**
     * New newsletter subscription action
     *
     * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
     */
    class NewAction extends SubscriberNewController {
    
    	/**
    	 * @var SubscriptionManagerInterface
    	 */
    	private $subscriptionManager;
    
    	/**
    	 * Initialize dependencies.
    	 *
    	 * @param Context $context
    	 * @param SubscriberFactory $subscriberFactory
    	 * @param Session $customerSession
    	 * @param StoreManagerInterface $storeManager
    	 * @param CustomerUrl $customerUrl
    	 * @param CustomerAccountManagement $customerAccountManagement
    	 * @param SubscriptionManagerInterface $subscriptionManager
    	 */
    	public function __construct(
    		Context $context,
    		SubscriberFactory $subscriberFactory,
    		Session $customerSession,
    		StoreManagerInterface $storeManager,
    		CustomerUrl $customerUrl,
    		CustomerAccountManagement $customerAccountManagement,
    		SubscriptionManagerInterface $subscriptionManager
    	) {
    
    		$this->subscriptionManager = $subscriptionManager;
    
    		parent::__construct(
    			$context,
    			$subscriberFactory,
    			$customerSession,
    			$storeManager,
    			$customerUrl,
    			$customerAccountManagement,
    			$subscriptionManager
    		);
    	}
    
    	/**
    	 * New subscription action
    	 *
    	 * @return Redirect
    	 */
    	public function execute() {
    
    		if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email')) {
    
    			$email = (string) $this->getRequest()->getPost('email');
    			$name = (string) $this->getRequest()->getPost('name');
    
    			try {
    
    				$this->validateEmailFormat($email);
    				$this->validateGuestSubscription();
    				$this->validateEmailAvailable($email);
    
    				$websiteId = (int) $this->_storeManager->getStore()->getWebsiteId();
    				/** @var Subscriber $subscriber */
    				$subscriber = $this->_subscriberFactory->create()->loadBySubscriberEmail($email, $websiteId);
    				if ($subscriber->getId()
    					&& (int) $subscriber->getSubscriberStatus() === Subscriber::STATUS_SUBSCRIBED) {
    					throw new LocalizedException(
    						__('This email address is already subscribed.')
    					);
    				}
    
    				$storeId = (int) $this->_storeManager->getStore()->getId();
    				$currentCustomerId = $this->getSessionCustomerId($email);
    				$subscriber = $currentCustomerId
    				? $this->subscriptionManager->subscribeCustomer($currentCustomerId, $storeId)
    				: $this->subscriptionManager->subscribe($email, $storeId);
    
    				if ($subscriber->getSubscriberId() > 0) {
    					$subscriber = $this->_subscriberFactory->create()->loadBySubscriberEmail($email, $websiteId);
    					$subscriber->setFullName($name)->save();
    				}
    
    				$message = $this->getSuccessMessage((int) $subscriber->getSubscriberStatus());
    				$this->messageManager->addSuccessMessage($message);
    			} catch (LocalizedException $e) {
    				$this->messageManager->addComplexErrorMessage(
    					'localizedSubscriptionErrorMessage',
    					['message' => $e->getMessage()]
    				);
    			} catch (Exception $e) {
    				$this->messageManager->addExceptionMessage($e, __('Something went wrong with the subscription.'));
    			}
    		}
    		/** @var Redirect $redirect */
    		$redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    		$redirectUrl = $this->_redirect->getRedirectUrl();
    		return $redirect->setUrl($redirectUrl);
    	}
    
    	/**
    	 * Get customer id from session if he is owner of the email
    	 *
    	 * @param string $email
    	 * @return int|null
    	 */
    	private function getSessionCustomerId(string $email):  ? int {
    		if (!$this->_customerSession->isLoggedIn()) {
    			return null;
    		}
    
    		$customer = $this->_customerSession->getCustomerDataObject();
    		if ($customer->getEmail() !== $email) {
    			return null;
    		}
    
    		return (int) $this->_customerSession->getId();
    	}
    
    	/**
    	 * Get success message
    	 *
    	 * @param int $status
    	 * @return Phrase
    	 */
    	private function getSuccessMessage(int $status) : Phrase {
    
    		if ($status === Subscriber::STATUS_NOT_ACTIVE) {
    
    			return __('The confirmation request has been sent.');
    		}
    
    		return __('Thank you for your subscription.');
    	}
    
    }
    

    Magemonkeys/Newsletter/view/adminhtml/layout/newsletter_subscriber_block.xml

    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <body>
        <referenceBlock name="adminhtml.newslettrer.subscriber.grid.columnSet">
          <block class="MagentoBackendBlockWidgetGridColumn" name="adminhtml.newslettrer.subscriber.grid.columnSet.full.name" as="full.name">
            <arguments>
              <argument name="header" xsi:type="string" translate="true">Name</argument>
              <argument name="index" xsi:type="string">full_name</argument>
              <argument name="header_css_class" xsi:type="string">col-name</argument>
              <argument name="column_css_class" xsi:type="string">ccol-name</argument>
            </arguments>
          </block>
        </referenceBlock>
      </body>
    </page>

    Magemonkeys/Newsletter/view/frontend/templates/subscribe.phtml

    <?php
    /** @var MagentoNewsletterBlockSubscribe $block */
    ?>
    <div class="block newsletter">
      <div class="title"><strong><?php /* @escapeNotVerified */ echo __('Newsletter') ?></strong></div>
      <div class="content">
        <form class="form subscribe"
              novalidate
              action="<?php echo $block->escapeUrl($block->getFormActionUrl()) ?>"
              method="post"
              data-mage-init='{"validation": {"errorClass": "mage-error"}}'
              id="newsletter-validate-detail">
          <div class="field full_name">
            <label class="label" for="full_name"><span><?php echo $block->escapeHtml(__('Name')) ?></span></label>
            <div class="control">
              <input name="full_name" type="text" id="full_name"
                     placeholder="<?php echo $block->escapeHtmlAttr(__('Name')) ?>"
                     data-validate="{required:true}"/>
            </div>
          </div>
          <div class="actions">
            <button class="action subscribe primary" title="<?php echo $block->escapeHtmlAttr(__('Subscribe')) ?>" type="submit">
              <span><?php echo $block->escapeHtml(__('Subscribe')) ?></span>
            </button>
          </div>
        </form>
      </div>
    </div>

    Result :

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote