#!/usr/bin/perl

use CGI qw(:standard);

# http header
print header;

if (! param()) {      # if the form hasn't been submitted yet...
   # the title
    print 
	start_html("So what's Been Eating (or at least Biting) You?"),
	h2("So what's Been Eating (or at least Biting) You?"),
	start_form,
	"What is your name? ", textfield('name'),
	p,
	"Select the type of animal: ",
	radio_group(-name=>'animal',
		    -values=>['dog','cat','bat','rat'],
		    -default=>'none'),
	p,
	"Were you hospitalized? ",
	popup_menu(-name=>'hospitalized',
		   -values=>['no','yes']),
	p,
	"What field equipment would most help protect you in the future: ", br,
	checkbox_group(-name=>'weapons',
                   -values=>['big stick','mace','small firearm','reinforced pants']),
	p,
	"Please describe the incident using colorful adjectives.",
	textarea(-name=>'comments', -rows=>4, -columns=>50),
	p,
	,submit(-name=>'action',-value=>'Submit Report'),
	end_form,
	hr;

}
# the form has been submitted
else {

    print 
	start_html("What's Been Eating (or at least Biting) You"),
	h2("What's Been Eating (or at least Biting) You"),
	h3("Thanks for your submission. The information you provided is:"),
	"Your name is ", em(param('name')),
        p,
        "The attacking beastie was a ", strong(param('animal')), ".",
	p,
        "Hospitalization required: ", strong(param('hospitalized')), ".",
	p,
        "Weaponry requested: ", strong(join(', ', param('weapons'))), ".",
        p,
        "What happened was: ", br, param('comments'),
        hr;

    open(S, ">>/tmp/soup");  # open a file to write to
    $CGI::Q->save(S);       # dump out all the form info
    close(S);               # close the file
}

# stuff to print if the form has been filled out or not

print
    address(
	    a({-href=>'mailto:dboldt@usgs.gov'}, 'Form Designer'),br,
	    
	    a({-href=>'http://water.usgs.gov/'}, 'WRD Home page')
    );

print end_html();

