3

I am just wondering why i am not getting the action Url in my Newsletter Subscribe form. I am calling the newsletter subscription form in my custom phtml file. I do get the form but when i inspect element the form action remains empty.

I am using the same code which is in subscribe.phtml

P.S I am calling the block like this in my custom phtml file.

include ($block->getTemplateFile('Magento_Newsletter::custom_subscribe.phtml'))

The custom_subscribe.phtml is my custom file with just change in style as i didn't tweak the main phtml.

2

I too faced the same problem and fixed by changing code in cms home page

Find this line :

{{block type="core/template" template="newsletter/subscribe.phtml"}}

and change it to :

{{block type="newsletter/subscribe" template="newsletter/subscribe.phtml"}}

Then define block in

 System > Permissions > Blocks

here add new block in this name newsletter/subscribe

After done above all you can get action url in newsletter form. Happy coding...

1

My guess is that your block is not extending the Magento\Newsletter\Block\Subscribe block.

The native subscribe template retrieves the form action URL by calling the following code:

$block->getFormActionUrl()

This method is declared in the block:

public function getFormActionUrl()
{
    return $this->getUrl('newsletter/subscriber/new', ['_secure' => true]);
}

Thus, if your block does not extend the original block this method cannot be called.

  • how can i extend my block? I am using custom custom block like this <container name="custom.footer" htmlTag="div" htmlClass="custom_footer" after="main.content"> <block class="Magento\Framework\View\Element\Template" name="mainfooter" template="Magento_Theme::html/footer_row.phtml"> </block> </container> In this phtml i am calling the newsletter block – kool_Coder May 23 '16 at 11:06

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.