
hybride
New User
Jul 26, 2009, 6:36 PM
Post #1 of 3
(370 views)
|
|
2 Forms on 1 page - session issue?
|
Can't Post
|
|
Hello everyone, This is my first post here, and I have been scratching my head over this for the past few weeks. I am currently teaching myself Perl and Prolog at the same time, and the code am working on requires both. What it's supposed to do is in the first query (the input), it checks whether or not the query exists in the file (that works). If it does, it continues on (works); if it does not, the second form with the yes/no radio buttons comes up (that also works). However, after pressing the radio button submit, the original query is lost, so somewhere between submit 1 and submit 2, the original query disappears. I have tried using sessions, but I only figured out how to make it on static variables, not with the dynamic param. I know this form requires sessions, but I have no idea how to do it with the second form. Any help would be greatly appreciated. This is the code:
#!/usr/bin/perl use strict; use warnings; use AI::Prolog; use AI::Prolog::Engine; use AI::Prolog::Term; use CGI; use CGI qw(:standard); use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; use CGI::Session; use Data::Dumper; use Tie::File; use Template; # for producing output. my $q = new CGI; #query, handle common gateway interface my $pq = CGI->new(); #query spiderform my $session = new CGI::Session(); my $CGISESSID = $session->id(); # These are the Prolog files, creating new prolog ruleset my $file = "ancestry.pl"; open(PROLOGFILE, $file ) or die "$! \n"; local $/; my $prologRules = <PROLOGFILE>; my $prolog = AI::Prolog->new( $prologRules ); print "Content-type: text/html\n\n"; firstQuery(); my $firstq = $q->param('query1'); #$session->save_param('que',$q->param('query1')); $session->save_param($q, ["query1","query2"]); my $que = $session->param('query1'); my $que2 = $session->param('query2'); #$session->param('query1'); #$session->param(-name=>'l_name', -value=>$firstq); if(param()) { my $t = $session->param("query1", $q->param("query1")); secondQuery(); if($q->param('submit2')) { print $que2; print 'es'; } } sub firstQuery { print <<PROG; <form method="post" name="prol1"> <input type="text" name="query1" maxlength="150"> <input type="submit" value="submit" name="submit1"> <input type="reset" value="erase"> </form> PROG } sub secondQuery { print <<PROG; <form method="post" name="prol2"> <input type="radio" name="query2" value="yes">Yes <input type="radio" name="query2" value="no">No<br /> <input type="submit" value="submit" name="submit2"> <input type="reset" value="erase"> </form> PROG }
|