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

Hi everyone, I recently started building a searchable website with perl. WIth the first script I create a subroutine that makes the forms (without frames) and I try to maintain state using the -action and -method statements. The next subroutine runs when a particular button has been pushed and creates frames, which should be filled out with 2 separate perl scripts. The problem is: when the frames are calling the perl scripts, state is not maintained. Is there any way of doing this (besides by saving and restoring state using "save(FH)" and "restore(FH)"? Here is the code:
my $CGI = new CGI(); #Create initial form &create_form($CGI) unless param(); #Get Action parm & go to appropriate subroutine my $action; if ($action = param('PDB')) { &show_pdb($CGI) } if ($action = param('RESULTS')) { &get_results($CGI) } #################subroutines sub create_form { my $query = shift; print $query->header("text/html"); print $query->start_html; print $query->start_form; print $query->p("Pick a PDB code\n"); print $query->popup_menu( -NAME=>'pdb', -VALUES=>\@keys, -DEFAULT=>" "); print $query->submit( -NAME=>'PDB', -LABEL=>'PDB info'); print $query->end_form; print $query->hr(); print $query->start_form(-method=>'POST', -action=>"./right2.p +l"); print $query->p("Pick a DOCK run to see the failures\n"); print $query->popup_menu( -NAME=>'results', -VALUES=>['DOCK4_FLEX_500', 'DOCK4_FLEX_5000', 'DOCK4_ +FLEX_50000']); print $query->submit( -NAME=>'RESULTS', -LABEL=>'Get results'); print $query->endform; print $query->hr(); print $query->end_html; } sub get_results { my $query = shift; print $query->header(); print $query->frameset({-cols=>'25%, 75%'}, frame({-name=>'left', -src=>"./left.pl", -method=>'POS +T'}), frame({-name=>'right', -src=>"./right2.pl", -action=>" +./right2.pl", -method=>'POST'}) ); }

Replies are listed 'Best First'.
Re: CGI: frames & maintaining state across CGI scripts
by crouchingpenguin (Priest) on Apr 15, 2003 at 13:03 UTC

    Yeah, what you want to do is pass some sort of session identifier to each frame. This will probably involve you writing session management capabilities into your script. A la:

    print $query->frameset({-cols=>'25%, 75%'}, frame({-name=>'left', -src=>"./left.pl?id=${identifier}", -method +=>'POS +T'}), frame({-name=>'right', -src=>"./right2.pl?id=${identifier}", -act +ion=>" +./right2.pl", -method=>'POST'}) );

    Then left.pl and right.pl know which session to lookup from your backend storage.


    cp
    ----
    "Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."
Re: CGI: frames & maintaining state across CGI scripts
by CountZero (Bishop) on Apr 15, 2003 at 06:01 UTC

    Just off the top of my head (I don't have the time to try it): perhaps using some 'hidden' form-fields or using 'GET' instread of 'POST' and adding the data you need to the URL?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law