2012-12-10 94 views
0

我想写显示在同一时间只有一个问题,每一个单独的页面上进行了调查。我无法弄清楚如何让我的CGI文件完成这个任务,现在我已经在一个页面上拥有了所有内容,但是希望我的用户能够点击“下一个”按钮来为他们提出一个新问题。我正试图用Perl和HTML来完成这项工作。例如:链接的网页与CGI脚本

use CGI qw(:standard);    # Include standard HTML and CGI functions 
use CGI::Carp qw(fatalsToBrowser);   # Send error messages to browser 

# 
# Start by printing the content-type, the title of the web page and a heading. 
# 

print header, start_html("Hello"), h1("Hello"); 


if (param()) {    # If true, the form has already been filled out. 

    $who = param("myname"); 
    $cats = param("cats");   # Extract the value passed from the form. 
    if($cats == "Y"){ 
     print p("Hello, your name is $who, and you like cats"); 
    } 
    else{ 
     print p("Hello, your name is $who, and you don't like cats"); # Print the name. 
    } 

} 
else {     # Else, first time through so present form. 

    print start_form();   
    print p("What's your name? ", textfield("myname")); 
    print p("Do you like cats? Y for yes and N for no", textfield("cats")); 
    print p(submit("Submit form"), reset("Clear form")); 
    print end_form(); 
} 

print end_html; 

如果我想猫质疑出现在接下来的页面上,通过取出提交按钮和一个推杆,其功能就像一个未来,我必须按钮链接到另一个页面或这可以在一个脚本中实现吗?简而言之,您是否可以创建并链接多个html页面以仅使用一个cgi脚本进行调查?

回答

3

当然可以。问题是你的脚本需要知道用户刚才提交了哪个页面,以便知道下一个要显示的页面。但是,您的<form>中隐藏的<input>可以轻松实现。这些隐藏的输入被浏览器发送到CGI脚本,就像它们是常规输入一样,例如,文本输入,下拉框或复选框。

在服务器端,此隐藏的<input>的名称和值可通过正常的param()方法调用获得。隐藏输入本身是用hidden()创建的;请阅读documentation available for it

+0

谢谢我一回家就会检查一下 –