Redirect After Form Submission

I have a view showing a list of database entries. Next to each entry is a delete button, to remove the record. When the user submits hits the delete button the go to a delete confirmation form (with yes/no submit buttons). The actual deletion is done in the deleteAction of the Controller. Normally I would, upon confirmation of deletion, simply redirect to a specified route using :

$this->redirect()->toRoute($route, ['action' => 'index']);

What I would like to do is redirect them back to the page they came from. I know I can redirect to the last page they were at with:

$url = $this->getRequest()->getHeader('Referer')->getUri(); return $this->redirect()->toUrl($url);
But this will return me to the delete confirmation page. Technically I would like to go two pages back. Is there a best practice for sending the route you would like to be returned to from within the form? When deleting a particular record from the table, the user can access this from multiple points, so simply redirecting to a static location is not an option.

Hello and welcome to our forums! :smiley:

If I understand your post correctly then you have one delete action for different types of contents and not 3 or more actions for deletion. Right?

You can use a hidden form element or the query string to transport the information from where the user is coming.

To clarify, I have one delete action for one record of data, but depending on the user they may access the information from multiple places (views).

I thought of passing the information in a hidden form field. I wouldn’t to throw the idea out to the masses and see if there were any other laminas-specific options available. Also, I try to keep my code as close to the industry standard as possible. I didn’t know if there was a generally accepted Best Practice for this procedure.

The handling is quite different. You will find solutions which uses the referer header, a session to save the target, a separate form element or something similar. The framework does not make any specifications here. The decision is yours. :wink: