0

我正在尝试编写一项调查,一次只显示一个问题,每个问题都在单独的页面上。我无法弄清楚如何让我的 CGI 文件完成此操作,现在我将所有内容都放在一个页面上,但希望我的用户能够点击“下一步”按钮将他们带到一个新问题。我正在尝试专门使用 Perl 和 HTML 来做到这一点。例如:

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 脚本进行调查吗?

4

1 回答 1

3

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

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

于 2012-12-10T08:09:49.060 回答