Important alert: (current site time 7/15/2013 9:27:39 PM EDT)
 

VB icon

Beginners web forms

Email
Submitted on: 10/10/2001 1:40:47 AM
By: Jolyon Bloomfield 
Level: Beginner
User Rating: By 2 Users
Compatibility: 5.0 (all versions), 4.0 (all versions), 3.0 (all versions)
Views: 12012
(About the author)
 
     Well, I'm just a beginner at Perl (i.e, 2 days), but I wrote a nice little script that puts up an HTML form with a submit button, then puts the submitted text on the screen. Seeing as there is minimal stuff for EXTREME NEWBIES! I thought I'd just add this in.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Beginners web forms
= Description:Well, I'm just a beginner at Perl (i.e, 2 days), but I wrote a nice little script that puts up an HTML form with a submit button, then puts the submitted text on the screen. Seeing as there is minimal stuff for EXTREME NEWBIES! I thought I'd just add this in.
= By: Jolyon Bloomfield
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=239&lngWId=6=for details.=**************************************

#!/usr/bin/perl
# 
# Form.cgi
# Puts a form on the screen with a textbox and a submit button.
# When submitted, takes the query string and places it back in the textbox.
# Also prints the query below the form.
# 
# By Jolyon Bloomfield, Jolyon_B@Hotmail.com, 10/10/2001
# 
my $title= "Hello there!";
print "Content-type: text/html \n\n";
%in=&parse;
$kwd=$in{'query'};
&printform;
if ($kwd) {
print "The query was: $kwd <br>";
}
&closehtml;
# Sorry about the below subroutine! I don't really know what it does, but it returns an array? of the data in the url line that is after the question mark. Somebody gave me this code...
sub parse {
my (@pairs, %in);my ($buffer, $pair, $name, $value);if ($ENV{'REQUEST_METHOD'} eq 'GET')
{@pairs = split(/&/, $ENV{'QUERY_STRING'});}elsif($ENV{'REQUEST_METHOD'} eq 'POST') {read(STDIN, $buffer,
$ENV{'CONTENT_LENGTH'});@pairs = split(/&/, $buffer);}PAIR: foreach $pair (@pairs) {($name, $value) = split(/=/,
$pair);$name =~ tr/+/ /;$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;$value =~ tr/+/ /;$value =~
s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;($value eq "---") and next PAIR;exists $in{$name} ? ($in{$name} .=
"~~$value") : ($in{$name} = $value);}return %in;
}
sub printform {
print <<"HTML code";
<html>
<head>
<title>$title</title>
</head>
<body>
<p>Here is my form!</p>
<p>
<form method=GET name="searchform">
<input name="query" value="$in{'query'}" type=TEXT size=15 maxlength=80>
 
<input type="submit" value="submit" name="submitbutton">
</form>
</p>
HTML code
}
sub closehtml {
print "</body>";
print "</html>";
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.