1

When we are saving any frontend form, it is showing the success message on same page and also on all other pages.

It also shows the messages after reload.

0

Your frontend controller save execute method success massage code should like this.

try {
    $model->save();
    $this->messageManager->addSuccess(__('The testimonial has been saved.'));
    if ($this->getRequest()->getParam('back')) {
        $this->_redirect('*/*/edit', array('testimonial_id' => $model->getId(), '_current' => true));
        return;
    }
    $this->_redirect('*/*/');
    return;
} catch (\Magento\Framework\Model\Exception $e) {
    $this->messageManager->addError($e->getMessage());
} catch (\RuntimeException $e) {
    $this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
    $this->messageManager->addException($e, __('Something went wrong while saving the testimonial.'));
}

$this->_getSession()->setFormData($data);
$this->_redirect('*/*/edit', array('testimonial_id' => $this->getRequest()->getParam('testimonial_id')));
return;

Hope this will help, I have also save my custom module testimonial data from frontend and I didn't get repeated success message.

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.