Redirect to editview from beforesave hook logic

I am trying to redirect from before save hook logic if an error occurs in it.It should redirect to edit view with error.I am using this code:

function ShowError($errorMsg,$beanID){
            try{
             SugarApplication::appendErrorMessage('An error has been occured: '.$errorMsg);
                    $params = array(
                      'module'=> 'ad123_Ads',
                      'action'=>'EditView', 
                      'id' => $beanID
                    );
            SugarApplication::redirect('index.php?' . http_build_query($params));
                }
        catch (Exception $e) {
              echo 'Caught exception: ',  $e, "\n";
            }
        
        }

But problem is after redirect all fields get unfilled.

That’s exactly what it’s supposed to happen. Remember that by redirecting you are canceling the current action.

The only way I can imagine to auto-fill the fields with the unsaved values is:

  1. Create a temporary table with the Account’s table structure (Including your custom fields)
  2. Nos modify your logichook to write current values to the temporary table only when the conditions to redirect are true
  3. Modify your file custom/Accounts/views/view.edit.php to query your table and prefill the fields with the saved values only when the user is the same to avoid other users to get somebody else’s values

Hope it gives an idea on how to solve this issue.

Thanks,

BrozTechnologies