来源:

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. handler消息机制

    MessageQueue代码:http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android ...

  2. ajax 跨域携带COOKIE

    这个问题属于Ajax跨域携带Cookie的问题,找了一篇博文的解决方案. 原生ajax请求方式: var xhr = new XMLHttpRequest(); xhr.open("POST ...

  3. awstats 日志分析

    /tmp/awstats/awstats.ezrydel.com.conf LogFile="/usr/local/apache/domlogs/ezrydel.com" php版 ...

  4. bootstrap复习:组件

    一.下拉菜单 1.实例:将下拉菜单触发器和下拉菜单都包裹在 .dropdown 里,或者另一个声明了 position: relative; 的元素.然后加入组成菜单的 HTML 代码.为下拉菜单的父 ...

  5. POJ 1922 Ride to School#贪心

    (- ̄▽ ̄)-* //C跟着a君骑,然后更快的b君来了,C又跟着b君骑, //接着最快的d君来了,C就去跟着d君了, //最后最快的d君到达目的地时,C也就到了 //所以C的到达时间,就是最早到达的那 ...

  6. Codeforces Round #367 (Div. 2) C. Hard problem

    题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...

  7. 如何提升 CSS 选择器性能

    CSS 选择器性能损耗来自? CSS选择器对性能的影响源于浏览器匹配选择器和文档元素时所消耗的时间,所以优化选择器的原则是应尽量避免使用消耗更多匹配时间的选择器.而在这之前我们需要了解CSS选择器匹配 ...

  8. 配置nginx为HTTPS服务器

    默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中.通常这 ...

  9. TCP协议中的三次握手和四次挥手(图解)【转】

    建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看如何建立连接的. [更新于2017.01.04 ]该部分内容配图有误,请大家见谅,正确的配图如下,错误配图也不删 ...

  10. 富文本ckediter

    ##<link rel='stylesheet' href='/css/index.css' /> <script type="text/javascript" ...