#!/usr/local/bin/perl # # Example 4-3. biopage.cgi use GD; use CGI; # First get the parameters passed into the script # Use the CGI module to parse the CGI form submission. my $q = new CGI; my $dob = $q->param('dob'); my $start = $q->param('start'); my $end = $q->param('end'); # Use the CGI module to create the HTML for the page # Print the header and opening tags print $q->header(-type => 'text/html'); print $q->start_html(-title => "Biorhythm!"); if ($dob && $start && $end) { # Output the html for the image tag. This passes the data # on to the bio.cgi script to generate the image data. print $q->h1("Your biorhythm from $start to $end"); print $q->img({ src => "biorhythm.cgi?". "dob=$dob&start=$start&end=$end", width => 500, height => 300 }); print $q->br; } else { # In this case, no data has been passed to the script; this # may be because this is the first invocation of the script or # blank fields were submitted. We can just print an # appropriate headline... print $q->h1('Get your biorhythms here!'); } # Print the form used to enter the dates print $q->start_form({ method => 'post', action => 'biopage.cgi' }), "Date of Birth:", $q->input({ type => 'text', name => 'dob', size => 10, value => $dob }), "Calculate biorhythms from ", $q->input({ type => 'text', name => 'start', size => 10, value => $start }), " to ", $q->input({ type => 'text', name => 'end', size => 10, value => $end }), $q->input({ type => 'submit', value => 'Give me my biorhythm!' }), $q->end_form(), $q->end_html();