Magento version: 2.1.8, problem occurred also in 2.1.5
Basically the problem is:
- I try to create a new account on the default
/customer/account/create/
page - I input an email with invalid TLD ([email protected])
- the validation throws an exception because it's invalid, it gets caught in
Magento\Customer\Controller\Account\CreatePost.php
and the message is added tothe _$messageManager_
- 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