Name: <INPUT SIZE=25 NAME="name" VALUE="Your name here">
Text area
<TEXTAREA NAME="comments" ROWS=3 COLS=50> I aint got nothin' to say </TEXTAREA>
Radio Buttons (choose one)
Age: <INPUT TYPE="radio" NAME="age" VALUE="unknown" CHECKED>Aint Sayin' <INPUT TYPE="radio" NAME="age" VALUE="under 40">Under 40 <INPUT TYPE="radio" NAME="age" VALUE="over 40">Over 40
Checkboxes (choose many)
I have: <INPUT type="checkbox" NAME="haveafish" CHECKED>A fish <INPUT type="checkbox" NAME="haveabird">A bird <INPUT type="checkbox" NAME="haveacat" CHECKED>A cat <INPUT type="checkbox" NAME="haveadog">A dog
Selection drop-down (choose one)
I prefer: <SELECT NAME="prefer"> <OPTION>Fish <OPTION>Birds <OPTION SELECTED>Cats <OPTION>Dogs </SELECT>
Selection list (choose one or chose many)
Today I want to: <SELECT NAME="todo" MULTIPLE SIZE=6> <OPTION SELECTED>Write HTML <OPTION>Go for a walk <OPTION>Eat cake <OPTION>Buy toys <OPTION>Plant a tree <OPTION SELECTED>Surf the internet <OPTION>Call my mom <OPTION>Read a book <OPTION>Quit my job </SELECT>
#!/usr/sbin/perl # # This script was originally written by Michael Toy, and modified # by Hagan Heller in March, 1995. # # The first line should be the path to "perl", which is the # language that this script was written in. If you don't have # perl, you can't run this. Also, MAKE SURE that the execute # permission is turned on for this file. # # # The information "returned" from this script must have a # type, so that Netscape will know what to do with it. The # type text/html tells it to display this as a document # # Anything that's print-ed after this shows up in the document. # print "Content-type: text/html\n\n"; print "<TITLE>Form Echo</TITLE>"; print "<H1>Form Echo</H1>"; print "<H2>Here is what you typed:</H2>\n"; # # This reads in the information sent when the user pressed Submit # if ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } # # Now, using a little loop, we'll split up the data into name/value # pairs, which makes them easier to work with. We'll also print out # each pair as it is created. # @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; print "<B>$name</B> = $value<BR>\n"; $FORM{$name} = $value; } # # As an extra bonus, here's how you get environment variables from # someone submitting a script. # print "<HR>"; print "<H2>Environment Variables</H2>\n"; foreach $item (keys %ENV) { print "<B>$item</B> = " . $ENV{"$item"} . "<BR>\n"; }; # # This script does something unusual: it prints out the name/value # pairs as they're being created. That's great for an echo demo, but # it's not really what you normally do. # # Once the name/value pairs have been created, you can work with # them by referring to the variable names you set up in the # original HTML. # print "<HR>"; print "<H2>A Real Example</H2>\n"; print "Dear <B>$FORM{name}</B>, <P>"; print "Thank you for visiting us from <B>$ENV{HTTP_REFERER}</B>. "; print "We are so happy to hear that you prefer <B>$FORM{prefer}</B>. "; print "We have some valuable products to offer you.";