xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/CGI/eg/frameset.cgi (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/local/bin/perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateuse CGI;
4*0Sstevel@tonic-gate$query = new CGI;
5*0Sstevel@tonic-gateprint $query->header;
6*0Sstevel@tonic-gate$TITLE="Frameset Example";
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gate# We use the path information to distinguish between calls
9*0Sstevel@tonic-gate# to the script to:
10*0Sstevel@tonic-gate# (1) create the frameset
11*0Sstevel@tonic-gate# (2) create the query form
12*0Sstevel@tonic-gate# (3) create the query response
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate$path_info = $query->path_info;
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gate# If no path information is provided, then we create
17*0Sstevel@tonic-gate# a side-by-side frame set
18*0Sstevel@tonic-gateif (!$path_info) {
19*0Sstevel@tonic-gate    &print_frameset;
20*0Sstevel@tonic-gate    exit 0;
21*0Sstevel@tonic-gate}
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gate# If we get here, then we either create the query form
24*0Sstevel@tonic-gate# or we create the response.
25*0Sstevel@tonic-gate&print_html_header;
26*0Sstevel@tonic-gate&print_query if $path_info=~/query/;
27*0Sstevel@tonic-gate&print_response if $path_info=~/response/;
28*0Sstevel@tonic-gate&print_end;
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate# Create the frameset
32*0Sstevel@tonic-gatesub print_frameset {
33*0Sstevel@tonic-gate    $script_name = $query->script_name;
34*0Sstevel@tonic-gate    print <<EOF;
35*0Sstevel@tonic-gate<html><head><title>$TITLE</title></head>
36*0Sstevel@tonic-gate<frameset cols="50,50">
37*0Sstevel@tonic-gate<frame src="$script_name/query" name="query">
38*0Sstevel@tonic-gate<frame src="$script_name/response" name="response">
39*0Sstevel@tonic-gate</frameset>
40*0Sstevel@tonic-gateEOF
41*0Sstevel@tonic-gate    ;
42*0Sstevel@tonic-gate    exit 0;
43*0Sstevel@tonic-gate}
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gatesub print_html_header {
46*0Sstevel@tonic-gate    print $query->start_html($TITLE);
47*0Sstevel@tonic-gate}
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gatesub print_end {
50*0Sstevel@tonic-gate    print qq{<P><hr><A HREF="../index.html" TARGET="_top">More Examples</A>};
51*0Sstevel@tonic-gate    print $query->end_html;
52*0Sstevel@tonic-gate}
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gatesub print_query {
55*0Sstevel@tonic-gate    $script_name = $query->script_name;
56*0Sstevel@tonic-gate    print "<H1>Frameset Query</H1>\n";
57*0Sstevel@tonic-gate    print $query->startform(-action=>"$script_name/response",-TARGET=>"response");
58*0Sstevel@tonic-gate    print "What's your name? ",$query->textfield('name');
59*0Sstevel@tonic-gate    print "<P>What's the combination?<P>",
60*0Sstevel@tonic-gate    $query->checkbox_group(-name=>'words',
61*0Sstevel@tonic-gate			       -values=>['eenie','meenie','minie','moe']);
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate    print "<P>What's your favorite color? ",
64*0Sstevel@tonic-gate    $query->popup_menu(-name=>'color',
65*0Sstevel@tonic-gate		       -values=>['red','green','blue','chartreuse']),
66*0Sstevel@tonic-gate    "<P>";
67*0Sstevel@tonic-gate    print $query->submit;
68*0Sstevel@tonic-gate    print $query->endform;
69*0Sstevel@tonic-gate}
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gatesub print_response {
72*0Sstevel@tonic-gate    print "<H1>Frameset Result</H1>\n";
73*0Sstevel@tonic-gate    unless ($query->param) {
74*0Sstevel@tonic-gate	print "<b>No query submitted yet.</b>";
75*0Sstevel@tonic-gate	return;
76*0Sstevel@tonic-gate    }
77*0Sstevel@tonic-gate    print "Your name is <EM>",$query->param(name),"</EM>\n";
78*0Sstevel@tonic-gate    print "<P>The keywords are: <EM>",join(", ",$query->param(words)),"</EM>\n";
79*0Sstevel@tonic-gate    print "<P>Your favorite color is <EM>",$query->param(color),"</EM>\n";
80*0Sstevel@tonic-gate}
81*0Sstevel@tonic-gate
82