Custom Module Form Redirect to Search Results Page

Working with secure zones and front-end Custom Module, Create and Update forms I have come across an issue when trying to redirect the form back to the search results that are on a separate page and keep the search results displayed.

I thought I would share my findings and maybe it will help others or maybe one of you will have a better way of doing it.

So if my form is on the same page as my Custom Module Search List then it is easy because you can use the following redirect to return to the search results after form submission.

<input type="hidden" name="redirectURL" value=" {{request.request_url.href}}">

However, using models can slow down page space for large modules.

When your form is on a separate page from your module list you can use this redirect, but it will redirect you back to the list and not your search results.

<input type="hidden" name="redirectURL" value=" {{request.request_data.referrer}} ">

So how do I get my form that is on a separate page to redirect back to my search results and not my unfiltered list? By using a URL parameter in your link to your form. Like this.

<a href=“/page-path?prop_url={{request.request_url.href | url_encode}}" >Edit</a>

As you can see I have the URL property here. Note the | url_endode without it this will not work if you have more than one parameter in the search URL you are grabbing.

Now on my form, my redirect looks like this.

<input type="hidden" name="redirectURL" value="{{request.request_url.params.prop_url | url_decode}}">

Again note the | url_decode is required to make this work.

Now after I edit a form I am redirected to my search results.

2 Likes