免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1978 | 回复: 2
打印 上一主题 下一主题

新手!请大家看看为什么这个CGI创建的多页窗口不能从第一页链接到下一页? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-02 23:32 |只看该作者 |倒序浏览
原代码如下:#!C:/Perl/bin/perl.exe -w
这个代码是我从一本书中打下来的。
目的是为了学习如何掌握隐含信息,如何使用窗口。
但是为什么当我点击第一页的submit后,并不能打开第二页呢?
请大家帮助解答。
use strict;
use Fcntl qw(:flock);
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
my $surveyfile="/tmp/survey.txt";
my @survey_answers=qw(pettype daytype clothes
                              castaway travel risky ownpet
                              realname comments);
my $semaphore_file="/tmp/survey.sem";
print header;
if(! param){
     page_one();
     }elsif(defined param('pageone')){
     page_two();
     }elsif(defined param('pagetwo')){
     page_three();
     }else{
     survey_done();
     }
sub page_one{
print "test";
    print<<END_PAGE_ONE;
    <FORM>
    Are you a "cat person" or a "dog person"?<BR>
    <INPUT type=radio name=pettype value=dog>Dog<BR>
    <INPUT type=radio name=pettype value=cat>Cat<BR>
    <P>
    Are you more of an early-riser or a night owl?<BR>
    <INPUT type=radio name=daytype value=earl>Early riser<BR>
    <INPUT type=radio name=daytype value=late>Night owl<BR>
    <P>
    At work, if you had a choice on how to dress....<BR>
    <INPUT type=radio name=clothes value=casual>Casual<BR>
    <INPUT type=radio name=clothes value=business>Business<BR>
    <P>
    If stranded on a desert island,
    who would you rather be stuck with?<BR>
    <INPUT type=radio name=castway value=ginger>Ginger<BR>
    <INPUT type=radio name=castway value=marya>Mary-Anne<BR>
    <INPUT type=radio name=castway value=prof>Professor<BR>
    <INPUT type=radio name=castway value=skipper>Skipper<BR>
    <INPUT type=submit name=pageone value="Next page">
</FORM>
END_PAGE_ONE
}

#
sub repeat_hidden{
print "test";
    foreach my $answer(@survey_answers){
            if(defined param($answer)){
                       print "<INPUT TYPE=hidden";
                       print "name=$answer";
                       print " value=\"",param($answer),"\">\n";
            }
    }
}
sub page_two{
    my $pet=param('pettype');
    if(!defined $pet){
                $pet="goldfish";
    }
    print<<END_PAGE_TWO;
    <FORM>
    Would you rather...<BR>
    <INPUTtype=radio name=travel value=travel>Travel<BR>
    <INPUT type=radio name=travel value=home>Stay at home<BR>
    <P>
    Do you consider yourself...<BR>
    <INPUT type=radio name=risky value=yes>A daredevi<BR>
    <INPUT type=radio name=risky value=no>Cautions<BR>
    <P>
    Do you own a $pet?<BR>
    <INPUT type=radio name=ownpet value=$pet>Yes<BR>
    <INPUT type=radio name=ownpet value=no>No<BR>
    <P>
    <INPUT TYPE=submit name=pagetwo value="Last Page">
END_PAGE_TWO
                repeat_hidden();
                print "</FORM>";
                }

    sub page_three{
       print "test";
        print<<END_PAGE_THREE;
        <FORM>
        last page! This information is optional!<BR>
        Your name:
        <INPUT TYPE=text name="realname"><BR>
        Any comments about this survey:<BR>
        <TEXTARE NAME=comments cols=40 rows=10>
        </TEXTAREA>
        <P>
        <INPUT type=submit name=pagethree
               value="submit survey results">
END_PAGE_THREE
                      repeat_hidden();
                      print "</FORM>";
    }
sub survey_done{
    save();
    print "Thanks You!";
}
#
# Save all of the survey results to $surveyfile
#
sub save{
    get_lock();
    open(SF,">>$surveyfile")||die "Cannot open $surveyfile: $!";
    foreach my $answer(@survey_answers){
            if (defined param ($answer)){
               print SF $answer,"-,param($answer)","\n";
                           }
}
close(SF);
release_lock();
}
#
#Locks and Unlocks the survey file so that multiple survey-takers
#Don't clash and write at the same time.
#

#Function to lock(watis indefinitely)
sub get_lock{
    open(SEM,">$semaphore_file")
     ||die "Cannot create semaphore:$!";
     flock SEM, LOCK_EX;
}

#
sub release_lock{
    close(SEM);
}

[[i] 本帖最后由 生物信息学 于 2009-9-2 23:33 编辑 [/i]]

论坛徽章:
0
2 [报告]
发表于 2009-09-02 23:35 |只看该作者

另外,请问有摘生物信息的同仁吗?

我是生物信息学研一的,期待和大家共同交流

论坛徽章:
0
3 [报告]
发表于 2009-09-03 00:13 |只看该作者
up
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP