in reply to redirect back to where you were

basically i am looking for an equivalent to javascripts history.back.

However there is a further snag. With javascript i had the history back function planted in the the same html script as the input form. Upon submiting the details, the form details would be processed and then the history.back would be executed taking me back to the page BEFORE the form page.

With 'print CGI::redirect($ENV{HTTP_REFERER})', because the cgi script is executed then the redirect is executed it itakes me back to the form page and not the page BEFORE.

In basic terms is there a simple way of jumping back two pages instead of one.

Costas

Replies are listed 'Best First'.
Re: Re: redirect back to where you were
by oakbox (Chaplain) on Jul 25, 2001 at 16:21 UTC
    You can jump back two pages if you dynamically generate the form from a cgi script. What I do is leave the electronic equivalent of bread crumbs.

    I put $ENV{'HTTP_REFERER'} into a hidden form field inside my dynamically generated form.

    <form> --------- stuff ---- <input type="hidden" name="backpage" value="$ENV{'HTTP_REFERER'}"> <input type="submit"> </form>
    Now you are free to redirect them in the final, form processing, script to CGI::redirect($input{'backpage'}).

    (Actually, I'm not so sure what CGI.pm puts it's input into, because I don't use it. But you get my meaning.)

    oakbox
    "If what I'm saying doesn't make sense, that's because sense cannot be made, it's something that must be sensed"-J.S. Hall

      I knew about JavaScript trick, but I like more trick with using $ENV{'HTTP_REFERER'} and will use it in my current project. Why? It works also if client disabled JavaScript (as I did recently).
      Quite often I'll also just add plain link (or submit button) like {Back to Main Menu} or {Close All Open Issues}, just to bypass multiple {BACK} commands and start fresh. Sometimes it's easier for users to start afresh.

      pmas
      To make errors is human. But to make million errors per second, you need a computer.

Re: Re: redirect back to where you were
by earthboundmisfit (Chaplain) on Jul 25, 2001 at 16:23 UTC
    Let's assume you go with the embedded JS. Simply output the script based on a condition of your post:
    # script head above if($q->param('f') eq 'done'){ print '<SCRIPT Language=\'JavaScript\'> history.go(-1) </SCRIPT>'; }
    In your HTML form simply place a hiden tag:
    <INPUT TYPE=hidden NAME=f VALUE=done>
    Similarly, you could place the CGI::redirect object within this conditional block. Forgive me if this is a simplistic response, but it's not very clear what you're after.