I have a submit form and a controller, with the execute method. At the moment, after sending the form, my page reloads and on top of the page I get an alert that notifies the user about the success or failure of the operation, how can I instead redirect to a custom sucess page?
The execute
method of my controller app/code/Vendor/Module/Controller/Order/Create.php
:
public function execute()
{
/** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$data = $this->getRequest()->getPostValue();
$sampleIds = explode(',', $data['sample_ids']);
if (count($sampleIds) > $this->helper->getMaxCount()) {
$this->messageManager->addError(__('The count of "samples" exceeds the limit'));
$data = null;
}
if ($data) {
/** @var VendorModuleModelOrder $model */
$model = $this->_objectManager->create('VendorModuleModelOrder');
$model->setData($data);
$model->setStoreId($this->_storeManager->getStore()->getId());
try {
$this->objectRepository->save($model);
$this->messageManager->addSuccess(__('Request was added to processing.'));
$this->dataPersistor->clear('vendor_sample_order');
// Send email
$this->helper->sendEmail($model);
} catch (MagentoFrameworkExceptionLocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while saving the data.'));
}
}
return $resultRedirect->setRefererOrBaseUrl();
}