来源:

http://www.cnblogs.com/itech/archive/2012/09/23/2698595.html

http://www.cnblogs.com/itech/archive/2012/10/31/2748044.html

一  此cgi既是提交前的form,也被用来处理form的提交

来自:http://www.devdaily.com/perl/perl-cgi-example-scrolling-list-html-form

代码: (多选listbox-Multiple-choice SELECTs实例)
不带参数时即为form:http://xxxx/cgi/perl-cgi2.cgi 
当点击form的submit提交时,实际上相当于:http://xxxx/cgi/perl-cgi2.cgi?languages=c&languages=html,此时为对form的处理结果

 #!/usr/bin/perl -Tw
#
# PROGRAM: scrolling_list.cgi
#
# PURPOSE: Demonstrate (1) how to create a scrolling_list form and
# (2) how to determine the value(s) selected by the user.
#
# Created by alvin alexander, devdaily.com.
# #-----------------------------------#
# 1. Create a new Perl CGI object #
#-----------------------------------# use CGI;
$query = new CGI; #----------------------------------#
# 2. Print the doctype statement #
#----------------------------------# print $query->header; #----------------------------------------------------#
# 3. Start the HTML doc, and give the page a title #
#----------------------------------------------------# print $query->start_html('My scrolling_list.cgi program'); #------------------------------------------------------------#
# 4a. If the program is called without any params, print #
# the scrolling_list form. #
#------------------------------------------------------------# if (!$query->param) { print $query->startform;
print $query->h3('Select your favorite programming language(s):');
print $query->scrolling_list(-name=>'languages',
-values=>[
'Basic',
'C',
'C++',
'Cobol',
'DHTML',
'Fortran',
'HTML',
'Korn Shell (Unix)',
'Perl',
'Java',
'JavaScript',
'Python',
'Ruby',
'Tcl/Tk'],
-size=>,
-multiple=>'true',
-default=>'Perl'); # Notes:
# ------
# "-multiple=>'true'" lets the user make multiple selections
# from the scrolling_list
# "-default" is optional
# "-size" lets you specify the number of visible rows in the list
# can also use an optional "-labels" parameter to let the user
# see labels you want them to see, while you use
# different names for each parameter in your program print $query->br;
print $query->submit(-value=>'Submit your favorite language(s)');
print $query->endform; } else { #----------------------------------------------------------#
# 4b. If the program is called with parameters, retrieve #
# the 'languages' parameter, assign it to an array #
# named $languages, then print the array with each #
# name separated by a <BR> tag. #
#----------------------------------------------------------# print $query->h3('Your favorite languages are:');
@languages = $query->param('languages');
print "<BLOCKQUOTE>\n";
foreach $language (@languages) {
print "$language<BR>";
}
print "</BLOCKQUOTE>\n"; } #--------------------------------------------------#
# 5. After either case above, end the HTML page. #
#--------------------------------------------------#
print $query->end_html;

二 也可以实现为html+perlcgi
代码:(多选checkbox实例)

 #colors.html
<html><head><title>favorite colors</title></head>
<body> <b>Pick a Color:</b><br> <form action="colors.cgi" method="POST">
<input type="checkbox" name="red" value=> Red<br>
<input type="checkbox" name="green" value=> Green<br>
<input type="checkbox" name="blue" value=> Blue<br>
<input type="checkbox" name="gold" value=> Gold<br>
<input type="submit">
</form>
</body>
</html> #colors.cgi
#!/usr/bin/perl -wT use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); print header;
print start_html; my @colors = ("red", "green", "blue", "gold");
foreach my $color (@colors) {
if (param($color)) {
print "You picked $color.<br>\n";
}
} print end_html;

其他实例radiobox

 #radiobox.html
<html><head><title>Pick a Color</title></head>
<body>
<b>Pick a Color:</b><br> <form action="radiobox.cgi" method="POST">
<input type="radio" name="color" value="red"> Red<br>
<input type="radio" name="color" value="green"> Green<br>
<input type="radio" name="color" value="blue"> Blue<br>
<input type="radio" name="color" value="gold"> Gold<br>
<input type="submit">
</form>
</body></html> #radiobox.cgi
#!/usr/bin/perl -wT
use strict;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my %colors = ( red => "#ff0000",
green => "#00ff00",
blue => "#0000ff",
gold => "#cccc00"); print header;
my $color = param('color'); # do some validation - be sure they picked a valid color
if (exists $colors{$color}) {
print start_html(-title=>"Results", -bgcolor=>$color);
print "You picked $color.<br>\n";
} else {
print start_html(-title=>"Results");
print "You didn't pick a color! (You picked '$color')";
}
print end_html;

三 cgi实例2

 #!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser); sub output_top($);
sub output_end($);
sub display_results($);
sub output_form($); my $q = new CGI; print $q->header(); # Output stylesheet, heading etc
output_top($q); if ($q->param()) {
# Parameters are defined, therefore the form has been submitted
display_results($q);
} else {
# We're here for the first time, display the form
output_form($q);
} # Output footer and end html
output_end($q); exit ; # Outputs the start html tag, stylesheet and heading
sub output_top($) {
my ($q) = @_;
print $q->start_html(
-title => 'A Questionaire',
-bgcolor => 'white',
} # Outputs a footer line and end html tags
sub output_end($) {
my ($q) = @_;
print $q->div("My Web Form");
print $q->end_html;
} # Displays the results of the form
sub display_results($) {
my ($q) = @_; my $username = $q->param('user_name');
print $username;
print $q->br; # Outputs a web form
sub output_form($) {
my ($q) = @_;
print $q->start_form(
-name => 'main',
-method => 'POST',
); print $q->start_table;
print $q->Tr(
$q->td('Name:'),
$q->td(
$q->textfield(-name => "user_name", -size => )
)
); print $q->Tr(
$q->td($q->submit(-value => 'Submit')),
$q->td('&nbsp;')
);
print $q->end_table;
print $q->end_form;
}

更多实例
http://www.cgi101.com/book/ch5/text.html 
http://www.comp.leeds.ac.uk/Perl/Cgi/forms.html

四 cgi实例3

 #!/usr/local/bin/perl
use CGI ':standard'; print header;
print start_html("Example CGI.pm Form");
print "<h1> Example CGI.pm Form</h1>\n";
print_prompt();
do_work();
print_tail();
print end_html; sub print_prompt {
print start_form;
print "<em>What's your name?</em><br>";
print textfield('name');
print checkbox('Not my real name'); print "<p><em>Where can you find English Sparrows?</em><br>";
print checkbox_group(
-name=>'Sparrow locations',
-values=>[England,France,Spain,Asia,Hoboken],
-linebreak=>'yes',
-defaults=>[England,Asia]); print "<p><em>How far can they fly?</em><br>",
radio_group(
-name=>'how far',
-values=>['10 ft','1 mile','10 miles','real far'],
-default=>'1 mile'); print "<p><em>What's your favorite color?</em> ";
print popup_menu(-name=>'Color',
-values=>['black','brown','red','yellow'],
-default=>'red'); print hidden('Reference','Monty Python and the Holy Grail'); print "<p><em>What have you got there?</em><br>";
print scrolling_list(
-name=>'possessions',
-values=>['A Coconut','A Grail','An Icon',
'A Sword','A Ticket'],
-size=>,
-multiple=>'true'); print "<p><em>Any parting comments?</em><br>";
print textarea(-name=>'Comments',
-rows=>,
-columns=>); print "<p>",reset;
print submit('Action','Shout');
print submit('Action','Scream');
print end_form;
print "<hr>\n";
} sub do_work { print "<h2>Here are the current settings in this form</h2>"; for my $key (param) {
print "<strong>$key</strong> -> ";
my @values = param($key);
print join(", ",@values),"<br>\n";
}
} sub print_tail {
print <<END;
<hr>
<address>Lincoln D. Stein</address><br>
<a href="/">Home Page</a>
END
}

具体的更多的form(checkbox,check_group,radio_group,popup_menu,hidden,scrolling_list,textarea.......), 在manpage search:  http://search.cpan.org/~markstos/CGI.pm-3.60/lib/CGI.pm

perl-cgi-form的更多相关文章

  1. Perl CGI编程

    http://www.runoob.com/perl/perl-cgi-programming.html 什么是CGI CGI 目前由NCSA维护,NCSA定义CGI如下: CGI(Common Ga ...

  2. 《Apache服务之php/perl/cgi语言的支持》RHEL6——服务的优先级

    安装php软件包: 安装文本浏览器 安装apache的帮助文档: 测试下是否ok 启动Apache服务关闭火墙: 编辑一个php测试页测试下: perl语言包默认系统已经安装了,直接测试下: Apac ...

  3. Perl &amp; Python编写CGI

    近期偶然玩了一下CGI,收集点资料写篇在这里留档. 如今想做HTTP Cache回归測试了,为了模拟不同的响应头及数据大小.就须要一个CGI按须要传回指定的响应头和内容.这是从老外的測试页面学习到的经 ...

  4. 转:perl源码审计

    转:http://www.cgisecurity.com/lib/sips.html Security Issues in Perl Scripts By Jordan Dimov (jdimov@c ...

  5. 25-Perl CGI编程

    1.Perl CGI编程什么是CGICGI 目前由NCSA维护,NCSA定义CGI如下:CGI(Common Gateway Interface),通用网关接口,它是一段程序,运行在服务器上如:HTT ...

  6. 第25章 项目6:使用CGI进行远程编辑

    初次实现 25-1 simple_edit.cgi --简单的网页编辑器 #!D:\Program Files\python27\python.exeimport cgiform = cgi.Fiel ...

  7. cgi创建web应用(一)之传递表单数据与返回html

    主旨: 0.环境说明 1.创建一个cgi本地服务 2.创建一个html表单页 3.创建一个对应的cgi 脚本文件 4.运行调试 0.环境说明: 系统:win7 32位家庭版 python:2.7 代码 ...

  8. 【转】Perl Unicode全攻略

    Perl Unicode全攻略 耐心看完本文,相信你今后在unicode处理上不会再有什么问题. 本文内容适用于perl 5.8及其以上版本. perl internal form 在Perl看来, ...

  9. Perl的调试方法

    来源: http://my.oschina.net/alphajay/blog/52172 http://www.cnblogs.com/baiyanhuang/archive/2009/11/09/ ...

  10. linux上通过lighttpd上跑一个C语言的CGI小页面以及所遇到的坑

    Common Gateway Interface如雷贯耳,遗憾的是一直以来都没玩过CGI,今天尝试一把.Tomcat可以是玩CGI的,但得改下配置.为了方便,直接使用一款更轻量级的web服务器ligh ...

随机推荐

  1. WPF关于“在“System.Windows.Markup.StaticResourceHolder”上提供值时引发了异常。”问题解决办法

    在WPF中添加样式,在MainWindow.xaml使用自定义按钮FButton时报错,报错信息如下: "System.Windows.Markup.XamlParseException&q ...

  2. Chapter 2 Open Book——23

    Mike interrupted us then — he was planning an epic battle of the blizzard in the parking lot after s ...

  3. cobaltstrike3.5使用记录

    一.服务器搭建与连接(1)团队服务器上: sudo ./teamserver 服务器IP 连接密码 (VPS的话要写外网ip,并且可以进行端口映射,默认使用50050端口) 但是这个一关闭团队服务器也 ...

  4. C语言:全局变量在多个c文件中公用的方法 [转]

    用C语言编写程序的时候,我们经常会遇到这样一种情况:希望在头文件中定义一个全局变量,然后包含到两个不同的c文件中,希望这个全局变量能在两个文件中共用. 举例说明:项目文件夹project下有main. ...

  5. 3、Web应用程序中的安全向量 -- cookie盗窃

    作为用户,为了防止cookie盗窃,可以在浏览器设置中选择"禁用cookie",但是这样做很可能导致在访问某个站点的时候弹出警告"该站点必须使用cookie". ...

  6. 【转】ActiveMQ与虚拟通道

    郑重提示,本文转载自http://shift-alt-ctrl.iteye.com/blog/2065436 ActiveMQ提供了虚拟通道的特性(Virtual Destination),它允许一个 ...

  7. 获取 Windows 任务栏 Rect

    获取当前Windows系统的任务栏尺寸 1: RECT rect; 2: HWND hwndTaskbar = FindWindow(TEXT("Shell_TrayWnd"), ...

  8. chapter8_1 编译执行和错误

    1.编译 前面介绍的,dofile是一个运行lua代码块的基本操作,实际上它是一个辅助函数. loadfile才真正做了核心的工作.dofile(打开文件,执行里面的代码块)和loadfile(从文件 ...

  9. javascript显式类型的转换

    显式类型转换目的:为了使代码变得清晰易读,而做显示类型的转换常使用的函数:Boolean(),String(),Number()或Object()如:Nunber(5) //5String(true) ...

  10. html5 画个圈

    <html><body><canvas id="myCanvas" width="200" height="100&qu ...