0

Magento2 I need to redirect to home page & display success msg after Submitting custom form in cart page.

I have written below code in my custom controller file but msg doesn't print on Home page only page gets redirect.

$this->messageManager->addSuccess(
                      __("Thank you for submitting your product enquiry . Our team will reach out to you as soon as possible.")
                            );

$resultRedirect = $this->resultRedirectFactory->create(); 
/** @return \Magento\Framework\Controller\Result\Redirect **/
return $resultRedirect->setPath('/');
1
  • there must be some customization done for the home page. – kunj May 7 '20 at 8:00
0

check below code

public function execute()
    {
        /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();
        try {
            $this->messageManager->addSuccessMessage(__('Submitted Successfully.'));
            return $resultRedirect->setPath('review/customer/review');
        } catch (\Exception $e) {
            $this->messageManager->addExceptionMessage($e, __('Something went wrong while.'));
            return $resultRedirect->setPath('*/*/');
        }

        return $resultRedirect->setPath('*/*/');
    }

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.