Hi guys,

OK, here is the issue I am having.
Perform a search and when you click the submit button, it takes you to the page that displays the info. Now, when the user clicks the back button on the browser it tries to re-submit the info. I don't want the info re-submitted, I just want the browser to take the user back to the relevant search page. Can I somehow trap the back button event and use that to redirect to a certain page?

Recommended Answers

All 2 Replies

While we don't trap the back button here on DaniWeb, we do trap leaving the page by any means possible (clicking a link, closing out the web browser, etc.) and we use jQuery to do so. Something similar to this ...

$(window).on('beforeunload',function() {  /* code here */  });

trapping the back button is not a good idea. I remember reading an article from the consortium entitled "Use standard redirects: Don't break the back button."

to prevent the form resubmission, we can place a session handler between the final form processor and the form page

form.php ----> sessionhandler.php (validates form and saves form data to session. If everything are valid, redirect user to the final processor) --> formprocessor.php ( process search requests. assign query and form submitted to session).

In the event, the user click on the back button.

formprocessor.php --> sessionhandler.php ( checks for the form submitted and the query. If these two are present, user redirected to the searchresult page. Else, the user is redirected to form page.)

forward flow:

form.php --> sessionhandler.php --> formprocessor.php

reverse flow:(pressing back button)

formprosessor.php -->(isset($_SESSION['submitted'] && isset($_SESSION['query']) ? 'redirect to result page' : 'redirect to form page';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.