I have a custom admin form, After click save button i am checking some unique url in my save controller. If the url is not unique, i want to pass an error message and redirected to the form with filed data. I tried to set referer url and its redirecting but my form data is cleared. Code part of my save controller. This is redirecting to the form but form data is cleared.

if (count($catData)!=0 && $faqCatId=='') {
        $this->messageManager->addErrorMessage("Url Key Already Exist.");
        $path = $this->_redirect->getRefererUrl();

1 Answer 1


to save the entered data of form content you need to use Session or functionality to achieve this.

Magento use Sessions to sort and store temporarily variables on the page. Example is:

 public function getFormData()
    $data = $this->getData('form_data');
    if ($data === null) {
        $formData = $this->_customerSession->getCustomerFormData(true);
        $data = new \Magento\Framework\DataObject();
        if ($formData) {
        if (isset($data['region_id'])) {
            $data['region_id'] = (int)$data['region_id'];
        $this->setData('form_data', $data);
    return $data;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.