Symfony 2: Save a referent for a form and redirect to it referer on submit

I have a list of entities with any filters (created, published, posted, etc) ... All these filters are sent using a GET request. As an example /list?createdAt=...&published=yes

. This is a list of pages and the page has pager elements. Each element has an edit button, and when clicked, a new page opens with an edit form. After submitting this form, I have to redirect the user to the last page (via filters, last page, etc.). How can I redirect the user to the last page (before editing)?

I see 2 solution:

  • Save url with GET request to store session. This solution has a problem: the store data was overwritten if I edit multiple (more than 2) objects at the same time.

  • Store the url in a hidden (virtual) field for this form, and on submit, I have a referent value.

Can any solution (Components, Bundles)?

+3


source to share


1 answer


If editing an item results in a new window being opened, the solution is to simply update the location of the opener on the page. Here's the basic idea:

// this would be one row HTML code from your main entity list
  <tr><td>Item 1</td><td>Some text ...</td><td><a href="#" onclick="window.open('editform.php');">Edit</a></td></tr>

      

Your popup edit form will need a JS procedure similar to the one sent to the browser when the action is saved:

<script type="text/javascript">
  window.opener.location.reload();
  // (optional) add an extra delay to present a save confirmation box before closing the popup
  setTimeout(function() { 
    window.close(); 
  }, 2000);

</script>

      


Another option is to redirect the user for editing to your edit form, in which case you do not have to worry about opening parallel edit forms with different filters set in the entity list. Just keep the referenced url inside the user session while editing:



$_SESSION['referrer']= $_SERVER['HTTP_REFERER'];

      

and undo and redirect with saving:

$referrer= $_SESSION['referrer'];
unset($_SESSION['referrer']);
header('Location: '.$referrer);

      

Note:

Just saw that the question was pretty old, so you probably found a solution. Would you close this question by posting your solution and accepting it as the answer?

-1


source







All Articles