来源:

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. link 与 @import之对比

    页面中使用CSS的方式主要有3种:行内添加定义style属性值,页面头部内嵌调用和外面链接调用,其中外面引用有两种:link和@import.外部引用CSS两种方式link和@import的方式分别是 ...

  2. tomcat Server.xml Context配置

    有时候需要在tomcat里面做特殊的配置,来进行访问: 例如你的程序 名字是hello端口是80  这时候你要访问你的程序 就要用 localhost/hello 来访问了. 但是怎么直接用 loca ...

  3. 关于c++中方法名前面的双冒号

    #include "iostream" using namespace std; template <typename T> void swap(T &a, T ...

  4. tomcat 7 启动超时设置。。。实在太隐蔽了

    打开Tomcat,选择 Window->Show View->Servers,在主窗口下的窗口中的Servers标签栏鼠标左键双击tomcat服务器名,例如 Tomcat v7.0 Ser ...

  5. SpringMVc上传excel或csv文件

    1.JSP页面代码 <form enctype=""multipart/form-data" method="post"> <inp ...

  6. C++ 类的继承、虚拟继承、隐藏、占用空间

    主函数: #include <iostream> #include "test.h" #include "testfuc.h" using name ...

  7. 利用pscp命令实现linux与windows文件互传

    windows==>linux(单个文件) PrivateKey.ppk(私钥)可以是相对路径或者绝对路径pscp -i D:\PrivateKey.ppk D:\xxx.xx root@123 ...

  8. python爬虫学习--防盗链

    一 首先要了解什么是盗链 盗链是指服务提供商自己不提供服务的内容,通过技术手段绕过其它有利益的最终用户界面(如广告),直接在自己的网站上向最终用户提供其它服务商的服务内容,骗取最终用户的浏览和点击率. ...

  9. spring框架--IOC容器,依赖注入

    思考: 1. 对象创建创建能否写死? 2. 对象创建细节 对象数量 action  多个   [维护成员变量] service 一个   [不需要维护公共变量] dao     一个   [不需要维护 ...

  10. 简单的JDBC连接oracle数据库例子

    java连接Oracle数据库 JDBC(Java Data Base Connectivity,java数据库连接),那么我们该如何用java进行数据库的连接呢. import java.sql.C ...