Jump to content

Two forms on one page in Perl


Recommended Posts

Am trying to get these two forms to work on my one page in Perl. When the first form submits, assuming the query is not in the Prolog file, it goes to the second form, which is a yes/no radio button submit. If yes, the query is sent again and appended; if no, the page does nothing. I know it has something to do with the @spres and the actual param being sent, because it works fine for the first part (seeing if the query is in the Prolog file), but when I have to actually submit the second form, the form goes blank, even if I have a simple print the param request (as is at the bottom of the code.)

 

I am trying to avoid doing to separate form pages, because even if I did manage the second page, after the query is done, the page would have to be sent back to the original form. Any help or ideas?

 

#!/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 ( '-ip_match' );
use Data::Dumper;

my $q = new CGI; #query, handle common gateway interface
my $pq = CGI->new(); #query spiderform
my $yn = CGI->new(); #query yes/no form

print "Content-type: text/html\n\n";

my $file = 'ancestry.pl';

open(PROLOGFILE, $file ) or die "$! \n";
local $/;
my $prologRules = <PROLOGFILE>;

my $prolog = AI::Prolog->new( $prologRules );

print <<PROG;

<form method="post" name="prol" action="loadanc.pl">
<input type="text" name="pqry" maxlength="150">
<input type="submit" value="send" name="sent">
<input type="reset" value="erase">
</form>

PROG

if($pq->param("sent")) {
my $prolq = param("pqry");
my @sp = split(/\W/,$prolq);

$prolog->query($prolq);
AI::Prolog::Engine->formatted(1); 

my ($results,@spres); #grab results, make array

while ($results = $prolog->results) {
	@spres = split(/\W/,$results);
	print "$spres[1] is the $spres[0] of $spres[3]<br>";							
	} #end while	


if (!@spres) {
	print "Failed: shall I add?";	

print <<QFORM;

<form method="post" name="yesno">
<input type="radio" name="sec" value="yes" />Yes
<input type="radio" name="sec" value="no" />No<br />

<input type="submit" value="send" name="ynquery">
<input type="reset" value="erase">
</form>
QFORM

if($pq->param("ynquery")) {
   print "test";
}
}

close( PROLOGFILE );

Link to comment
https://forums.phpfreaks.com/topic/164805-two-forms-on-one-page-in-perl/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.