Sinatra - 如何最好地在页面之间移动变量/参数
我有一个注册页面,其中包含常用的电子邮件、姓名、密码……该页面在服务器提交的路由/页面中进行了验证。如果失败,那么我重定向回来,但我想将值填回到注册页面中。我可以将注册表单参数放入会话中,但它将保留在那里...是否有页面内存(范围比会话更小) )就像会话一样,它仅用于下一页,然后消失/这是实现此目的的最佳方法。
谢谢
I have a register page with the usual email,name,password ..which is validated in the server's submitted route/page. if it fails then I redirect back but I want to fill the values back in the register page..I can put the register form parameters in the session but it will stay there...is there a page memory(a smaller scope than session) just like session which will be just for the next page and then gone/ which is the best way to implement this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不直接从 POST 路由渲染注册页面,如下所示:
然后在您的视图中,填充
@registration_data
(如果存在)。此外,您还可以使用
session.clear
清除会话数据。Why don't you just render the registration page from the POST route like this:
Then in your view, have it fill in
@registration_data
if it exists.Also, you can clear session data with
session.clear
.Ajax 验证会容易得多。您只需向表单提交按钮注册一个 onclick 事件,该事件会调用一个页面,该页面返回带有错误信息的 json 状态代码,或者返回 200 表示“正常”。如果是200,则提交。
Ajax validation would be much easier. You just register an onclick event to your form submit button that makes a call to a page that returns a json status code with the error information or 200 for OK. If 200, then submit.