【问题标题】:Linking pages with CGI scripts使用 CGI 脚本链接页面
【发布时间】:2012-12-10 03:39:10
【问题描述】:

我正在尝试编写一次仅显示一个问题的调查,每个问题都在单独的页面上。我不知道如何让我的 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 脚本进行调查吗?

【问题讨论】:

    标签: perl cgi


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,我一回家就去看看
    猜你喜欢
    • 2013-11-21
    • 2016-09-20
    • 2013-05-12
    • 2013-12-20
    • 2013-03-21
    • 1970-01-01
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    相关资源
    最近更新 更多