I am absolutely new in magento. I have made new input called 'name' under email input in


<div class="block newsletter">
<div class="title"><strong><?= $block->escapeHtml(__('Newsletter')) ?></strong></div>
<div class="content">
    <form class="form subscribe"
        action="<?= $block->escapeUrl($block->getFormActionUrl()) ?>"
        data-mage-init='{"validation": {"errorClass": "mage-error"}}'
        <div class="field newsletter">
            <label class="label" for="newsletter"><span><?= $block->escapeHtml(__('Sign Up for Our Newsletter:')) ?></span></label>
            <div class="control">
                <input name="email" type="email" id="newsletter"
                       placeholder="<?= $block->escapeHtml(__('Enter your email address')) ?>"
                       data-validate="{required:true, 'validate-email':true}"/>
                <input name="name" placeholder="Name"/>

        <div class="actions">
            <button class="action subscribe primary" title="<?= $block->escapeHtmlAttr(__('Subscribe')) ?>" type="submit">
                <span><?= $block->escapeHtml(__('Subscribe')) ?></span>

I have made a new column in newsletter_subscriber table in


class UpgradeSchema implements UpgradeSchemaInterface


public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    if (version_compare($context->getVersion(), '0.0.2', '<')) {
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => 50,
                'nullable' => false,
                'default' => '',
                'comment' => 'Name'


And this is my controller in


namespace Magebit\Newsletter\Controller\Subscriber;

class NewAction extends 
    public function execute() {
        $name = $this->getRequest()->getPost();

For now controller var_dump's input value.

What I want to achieve is to save input value into "name" column in 'newsletter_subscriber' table.

Can't get it right. What should I do next?

  • It might be usefull to set the new field as nullable if you have old data in your table. With a nullable field the proposed first approach would work. With a not nullable field please use the second approach in my answer and implement the subscribe($email, $name) method. Please let me know if this works for you or if you need further help – HelgeB Feb 16 '19 at 19:08
  • Yes, thank you, it helped! I am pretty sure, that I will have a lot of questions in nearest future! – Rufus Feb 17 '19 at 9:57

If you want to implement the logic in your controller, you have to copy the execute() method from the original, inherited controller and load the subscriber object after it was created, add your attribute and save the object. For this you have to add the following lines right after the subscribe() method has been called:

$status = (int) $this->_subscriberFactory->create()->subscribe($email);
//your code starts here...
$newSubscriber = $this->_subscriberFactory->create()->loadByEmail($email);

I hope that helps. Anyway there are other possibilities to do this, for example creating a new method subscribe($email, $name) in the subscriber object and call that from your controller. With that approach you don't need to load the subscriber in the controller after creation, but you have to overwrite the subscriber model.

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.