Magento 2 submit contact form not showing success/error messages

Viewed 1260

I'm using Magento 2.4.2 on a website with multiple stores where I have :

  • example.com/fr
  • example.com/es
  • example.com/us/en
  • ...

My issue is when someone submit on the contact form, no success or error message is displayed, and the div that should contain it is empty (not a css issue).

Other messages such as add to cart success or bundle select option are well displayed on each stores.

I tried to debug it and I found something with cookies:

When going for the first time on example.com/fr/contact, I will have the cookie "mage_messages" with no value, 'example.com' as domain and '/fr' as path. When submiting, a new cookie "mage_messages" is created with the success message encoded as value, 'example.com' as domain and '/' as path. The first cookie "mage_messages" is same as before submitting

I tried to force set the encoded value in the cookie with path '/fr' and the messages appeared after refresh.

It seems that Magento is setting a cookie with wrong path, that cause the creation of a new one with the wanted value.

When the bug appeared, the "cookie path" config was empty. I tried to set it as '/' or '/fr' but it had no effect so I let it empty.

Could you please help me to find out what is happening?

1 Answers

If someone else has this issue, I finally found a solution a few months after I posted the issue (it's my other account).

My solution :

The issue was on a subdomain like subdomain.domain.com and the issue was caused by cookie configuration for subdomains.

In Store > Configuration > Web > Default Cookie Settings :

  • Set Cookie Path to /
  • Set Cookie Domain to subdomain.domain.com

Then clear cache with php bin/magento cache:flush and go on front on the page where messages are not showing, clear cookies in browser and refresh.

It should be corrected.

Related