0

Magento version: 2.1.8, problem occurred also in 2.1.5

Basically the problem is:

  1. I try to create a new account on the default /customer/account/create/ page
  2. I input an email with invalid TLD ([email protected])
  3. the validation throws an exception because it's invalid, it gets caught in Magento\Customer\Controller\Account\CreatePost.php and the message is added to the _$messageManager_
  4. after the redirect there's no messages

Until the return of the execute method the message is inside the $messageManager but after that it gets lost somewhere because I don't receive it on the frontend.

To try and debug, I injected the messageManager into the Register.php block, created a function to retrieve messages as such

public function getMessages()
{
    $messages = array();
    $collection = $this->messageManager->getMessages(true);
    if ($collection && $collection->getItems()) {
        foreach ($collection->getItems() as $message) {
            $messages[] = $message->getText();
        }
    }
    return $messages;
}

and then I print it in the form (in register.phtml)

echo print_r($block->getMessages(), true);

but it's always an empty array

I am using a custom template, but I also tried with the default one and still same situation and all the backend part is default, so I believe the problem is somewhere in Magento.

I also added

<referenceContainer name="page.messages">
    <block class="Magento\Framework\View\Element\Template" name="ajax.message.placeholder" template="Magento_Theme::html/messages.phtml"/>
    <block class="Magento\Framework\View\Element\Messages" name="messages" as="messages" template="Magento_Theme::messages.phtml"/>
</referenceContainer>

to the customer_account_create.xml layout, but of course doesn't work if there are no messages. Simply adding this to other pages inside the site works fine

2
  • The error messages should be passed in a cookie with the response. Check there to determine if the issue is server side or in the template/js.
    – Pmclain
    Aug 19, 2017 at 1:53
  • @Pmclain I just checked and the mage-messages cookie is set a little bit after I submit the form but on the redirect it gets deleted
    – Marcus
    Aug 21, 2017 at 7:46

1 Answer 1

0

In the end the problem was stupid... the theme and parent theme were overriding the messages.phtml, I deleted the file in the custom themes and now it works.

I'm still new to Magento and I'm working on an existing project, so I had to dive in. So by learning from my mistake I'd say to disable custom themes in case basic functionality isn't working to check if it's the theme or not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.