[英]How can I make an HTML/NodeJS form go to another form based on a response, sort of like Google Form's "Go to section based on answer?"
So I have a NodeJS site and on the home page is a form containing some radio buttons.所以我有一个 NodeJS 站点,主页上有一个包含一些单选按钮的表单。 When the user clicks "Submit," I would like for the user to be redirected to another page based on the answer.
当用户单击“提交”时,我希望根据答案将用户重定向到另一个页面。 This I have figured out (The buttons have an
onclick
attribute that changes the action
attribute of the form element).我已经弄清楚了(按钮有一个
onclick
属性,可以更改表单元素的action
属性)。 However, I need to keep the data from the original form, so that after the user has "chosen their path," I know what path the took and the answers they made along it.但是,我需要保留原始表单中的数据,以便在用户“选择他们的路径”之后,我知道他们选择了哪条路径以及他们沿着这条路径做出的答案。 Thank you in advance!
先感谢您!
You could persist the client's state in a session.您可以在会话中保留客户端的状态。 If you're using express, one alternative could be
express-session
.如果您使用的是 express,另一种选择是
express-session
。 The way it works is that it assigns a unique identifier to the user in the form of a cookie and saves the data somewhere (memory, database, a file, etc. depending on which you choose).它的工作方式是,它以 cookie 的形式为用户分配一个唯一标识符,并将数据保存在某个地方(内存、数据库、文件等,具体取决于您选择的位置)。 Then when the client makes another request, the server gets that data back with the identifier from the cookie.
然后,当客户端发出另一个请求时,服务器会使用 cookie 中的标识符取回该数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.