一次显示调查问题 1
我正在编写一项调查,应一次显示每个问题。我对表单的具体工作方式有点生疏,所以这可能是问题所在,但这是我的问题。
该程序从文件中读取问题并将其显示在页面上。本质上,我想使用一个表单来显示问题,通过下一个或上一个按钮提交答案,然后从那里转到下一个问题。
值得注意的是我必须使用CGI(虽然我认为这影响不大)。
据我了解,我必须使用某种隐藏字段来跟踪当前的问题编号,这准确吗?
I'm writing a survey that should display each question one at a time. I'm a little rusty on how exactly forms work, so that may be the issue but here's my question.
The program reads the questions from a file and displays them on the page. Essentially I want to use a form to display a question, subit the answer via a next or previous button, and go to the next question from there.
Worth noting is that I must use CGI (although I don't think this effects much).
From what I understand I have to use some sort of hidden field to keep track of the current question number, is this accurate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 CPAN 有一个名为 CGI::Session 的模块。正如您可能猜到的那样,该模块处理会话管理。这样做有助于维护 CGI 应用程序中的状态。除非您的需求将您引向 CGI::Session 未明确涵盖的方向,否则建议您让它为您完成会话/状态管理的繁重工作。
虽然可以使用隐藏字段将信息从一个状态传递到下一个状态,但有一些方法比其他方法更可靠。隐藏字段只是多种技术中的一种。 GET 请求可以将会话信息从一个请求传递到下一个请求。隐藏字段也是如此。饼干也是。但是,传递标识特定会话的哈希值通常比传递当前和下一个问题编号更好。对于某人来说,以您的脚本不打算处理的方式进行操作会更困难。本段的要点是 CGI::Session 让您不必太担心会话管理的实现。这可以让您腾出时间专注于完成某件事(Web 应用程序的主要目的)。
From CPAN there is a module called CGI::Session. This module handles, as you might guess, session management. In so doing, it facilitates maintaining state in your CGI applications. Unless your needs take you an a direction that is specifically not covered by CGI::Session, you're well-advised to let it do the heavy lifting on session/state management for you.
While it is possible to pass information from one state to the next using hidden fields, there are ways to do it that are more reliable than others. And hidden fields are only one of several techniques. GET requests may pass session info from one request to the next. Hidden fields as well. Cookies too. But rather than passing the current and next question number, it's often better to pass a hash value that identifies a particular session. That is harder for someone to manipulate in ways that your script doesn't intend to deal with. The point to this paragraph is that CGI::Session lets you not worry so much about the implementation of your session management. That frees you up to concentrate on getting something done (the primary purpose of the web application).
有多种方法可以进行会话管理,不要依赖于将内容存储在“隐藏”字段中。为什么不将响应写回数据库?这样,如果第一次没有完成调查,人们可以恢复调查。
There are several ways of doing session management, don't rely on storing things in 'hidden' fields. Why not write back the responses to a database? That way people could resume surveys if they didn't finish them first time round.