Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

CGI - Keep'em quiet page?

by TommyGun (Novice)
on Jun 16, 2001 at 18:34 UTC ( [id://89051]=perlquestion: print w/replies, xml ) Need Help??

TommyGun has asked for the wisdom of the Perl Monks concerning the following question:

Not sure wether can do this...

On posting of form to CGI, I want to return a 'please wait' page (I can do that!).
The same script continues on with processing the form,
and then, on completion,
moves the client's browser to a new 'results' page.

Without using two scripts, am I just being lazy?
Or is there a handy little HTTP response that tells the browser to stop creating the current page and start a new one.

Any insight greatly appreciated,
TommyGun.

Replies are listed 'Best First'.
(ar0n: see column) Re: CGI - Keep'em quiet page?
by ar0n (Priest) on Jun 16, 2001 at 18:48 UTC
    Just coincidentally, I wrote a column on that back in December '97. {grin}

    Ok, so I didn't write it. merlyn did. I just wondered what it felt like.

    ar0n ]

Re: CGI - Keep'em quiet page?
by nysus (Parson) on Jun 16, 2001 at 19:11 UTC
    First if you are looking for a real Perl soultion you'll want to check out merlyn's article here.

    I had a similar desire to accomplish the same thing as you a few months ago but not a Perl guru, I did the following bit of trickery:

    When the form gets submitted, you get redirected to a two-framed page. The top frame has a width of 0 so it won't be seen by the user. The top frame is also an .shtml page and contains a server side include to the script that will process the form. The bottom frame will contains the "Please Wait" message. So while your top frame is doing it's work, the bottom frame will display the message.

    Now here's the real trick: you have your Perl code generate a bit of javascript at the very end of the Perl code (the one called by the top frame) that will redirect the browser to your desired page and replace the two-framed layout with a one framed layout. In case the user doesn't have javascript, you also have the Perl script generate <noscript> tags and have them click a link to take them to the page you want them to get to.

    So now, when the Perl is done doing it's stuff, it will generate some js code an put it into the top frame, and then user will get automatically redirected (with js enabled) or they will be requested to click a link to continue on.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot";
    $nysus = $PM . $MCF;

Re: CGI - Keep'em quiet page?
by nysus (Parson) on Jun 16, 2001 at 20:52 UTC
    I think I may have a more elegant solution for you:
    #!/usr/bin/perl -w use strict; $|++; BEGIN{ use CGI qw(:standard); print header; print start_html; print "Please wait"; print end_html; } sleep 5; # Code that process form would actually go here require Perl_file_that_redirects_browser_goes_here.pl; # Above line simply calls a Perl file that uses CGI.pm "redirect" func +tion to redirect the browser to the desired page.

    This is untested but I don't see a reason why it wouldn't work.

    Update: After some testing, this isn't working because the redirect gets printed to the HTML page instead of redirecting the browser because it is called after the content header. I naively assumed using calling another script with "require" would solve this problem but it doesn't. Anyone else have any ideas on how to redirect the browser?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot";
    $nysus = $PM . $MCF;

      Above line simply calls a Perl file that uses CGI.pm "redirect" function to redirect the browser to the desired page.

      That won't work because CGI.pm's redirect() prints out HTTP headers to redirect the client. But you've already printed out HTTP headers, so the redirect headers will be included in the text rendered by the browser. So the user will see:

      Please wait
      Status: 302 Moved
      location: http://path/to/redirect

      If you'll want to redirect in that manner you'll have to use JavaScript.

Re: CGI - Keep'em quiet page?
by shotgunefx (Parson) on Jun 17, 2001 at 00:00 UTC
    I posted a reply to another node that started off of a discussion about this one that you may find helpful.

    -Lee

    "To be civilized is to deny one's nature."
Re: CGI - Keep'em quiet page?
by mattr (Curate) on Jun 18, 2001 at 13:59 UTC
    I've done this with only one frame by having the user first go to a static html page with javascript in the head.

    The javascript checks a cookie and does a redirect to either a separate static page or to the cgi program.

    You can do the same with a perl program by having it output the static html, or outputting the redirect, but you can't (as far as I know) set a cookie and do a redirect simultaneously from Perl.

    Also it would be good to provide static links on the temporary page just in case redirection fails, i.e. no javascript or cookies accepted in user's browser, or failure of some useful javascript code due to browser version. By the way you can also modify the javascript on the fly if outputted from a Perl program.

      Of course you can redirect with cookie. CGI::redirect accepts the same parameter as CGI::header.
        Sorry, perhaps I am corrected. I have had many problems getting cookie and redirect headers to be printed out together and actually followed (from CGI.pm), and have heard similar things from other people. I wouldn't want to be spreading FUD. Has anyone had the same? Please disregard that part until there is some corroboration one way or other since I know what I've seen. Perhaps old version of CGI.pm?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://89051]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-18 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found