来源:

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. weex 语法高亮

    @1.ctrl+shift+p,调出控制命令面板,@2.输入pic,点击进入 @3.输入vue Syntax Highlight,等待下载 所有的sublime下载插件同理. vue Syntax H ...

  2. android 5.0 -- Ripple 效果

    Ripple 水波纹效果,也就是涟漪效果. 波纹效果有两种: 1,波纹有边界:波纹涟漪效果只是显示在控件内部 android:background="?android:attr/select ...

  3. HDU 5834 Magic boy Bi Luo with his excited tree

    树形dp. 先dfs一次处理子树上的最优解,记录一下回到这个点和不回到这个点的最优解. 然后从上到下可以推出所有答案.细节较多,很容易写错. #pragma comment(linker, " ...

  4. HDU1009FatMouse' Trade(贪心)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  5. hdu_5874_Friends and Enemies(公式题)

    题目链接:hdu_5874_Friends and Enemies 题意: 有nn个人, mm种颜色的石头, 人两两之间要么是朋友, 要么是敌人. 每个人可以携带若干种石头或者不带, 要求朋友之间至少 ...

  6. Docker安装目录

    操作系统为 # cat /etc/redhat-release CentOS Linux release (Core) docker安装 # yum install -y docker docker安 ...

  7. Java 字符串比较,String 中的一些方法 == 和 equals 的详解

    "==" 是比较的是两个对象的内存地址,而equals方法默认情况下是比较两个对象的内存地址. 1.String str = "hello"  生成的字符串,首 ...

  8. 防暴力破解 Fail2Ban之python

    fai2ban的介绍 fail2ban可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是调用防火墙屏蔽),如:当有人在试探你的SSH.SMTP.FTP密码,只要 ...

  9. 工具类 util.img

        /**     * @description transform emotion image url between code     * @author x.radish     * @pa ...

  10. VMware 下的Linux系统远程连接putty

    ifconfig查看ip地址 虚拟网卡需要自己新建  nat8 putty不能显示中文的解决办法 http://jingyan.baidu.com/article/5552ef47df8a97518f ...