如何在单独页面上存储表单数据的部分? [英] How to store parts of form-data when they're on separate pages?

查看:137
本文介绍了如何在单独页面上存储表单数据的部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我为客户准备一个长表单时,我总是希望将其拆分成单独的页面,因此访问者不必填写所有内容,而是逐步执行。



类似:

 步骤1>步骤2>步骤3>谢谢! 

我从来没有做过一个原因:我不知道如何存储数据单独的步骤有效吗?我的意思是,如何存储它,所以当访问者决定不在步骤3完成它所有的数据被删除。



我想出了几个


  1. 存储表单数据库中的数据

    我可以想象一个表格,其中列表示每个问题,最后一列表示 bool 完成还是不完成?

    但是我必须每隔一段时间(即使每次更新新数据时)清理表格,并删除所有条目 complete = 0

  2. 在会话数据中存储表单数据。 $ b另一方面,不必在数据库中存储数据(取决于会话的处理方式),所有信息都在Cookie中。但是,如果浏览器不支持cookies或用户禁用它(很少,但发生),或者如果表单有文件附件,那么这是一个没有去。


  3. echo 从上一页的表单数据< input type =hidden> 下一页

    是的,我知道这是一个相当愚蠢的想法,但它是一个替代方案。很差,但却是。


选项 1 是最好的,但我觉得没有必要在DB中存储临时数据。如果这成为一个非常受欢迎的形式,有很多游客填充它?更新/删除的数量可能是巨大的?



我想知道如何处理它。






编辑



David问了一个好问题。我使用什么技术?

我个人使用PHP + MySQL,但我觉得这是更通用的问题。请分享您的解决方案,无论您使用什么服务器端技术,我相信这个概念可以适应一种方式或其他的不同的技术。

解决方案

我认为选项1和2之间的选择取决于您存储的数据量。我认为在大多数情况下,您在表单上收集的数据量将是相当小(几千字节)。在这种情况下,我认为将其存储在会话数据中是一种方式。在传递那么多的数据来回没有太多的开销。此外,除非您的用户在有严格的安全策略的计算机上,应用程序应该工作。如果您提出页面要求,用户可以决定是否要继续操作。



如果您要为表单存储大量数据,则数据库会更好所以你不需要来回传递数据。但是,我认为这将是一个相当罕见的情况。即使应用程序允许上传文件,您也可以将它们保存到临时位置,并在表单完成后将它们写入数据库。您可能想要使用数据库的其他情况是,您的表单需要能够支持用户离开并稍后恢复以恢复表单。


Whenever I'm to prepare a long form for the client I always want to split it into separate pages, so the visitor doesn't have to fill it all, but does it in steps.

Something like:

Step 1  >  Step 2  > Step 3 > Thank You!

I've never done it for one reason: I don't know how to store the data from separate steps efficiently? By efficiently I mean, how to store it, so when a visitor decides not to finish it at Step 3 all the data is deleted.

I've come up with few ways of how this could be resolved, but I'm just not convinced by any of them:

  1. Storing form data in database
    I can imagine a table with columns representing each question, with final column representing a bool value whether the form has been completed or not?
    But I would have to do a clean-up of the table every now and then (maybe even every time it gets updated with new data?) and delete all entries with complete = 0.

  2. Store form data in session data.
    This on the other hand, does not have to store data in database (depending on how sessions are being handled) and all info would be in Cookie. But what if browser doesn't support cookies or user disabled them (rare, but happens), or if form has file attachments, then this is a no-go.

  3. echo'ing form data from previous page as <input type="hidden"> on the next page
    Yes, I'm aware this is a rather stupid idea, but it's an alternative. Poor, but it is.

Option 1 seems to be the best, but I feel it's unnecessary to store temporary data in DB. And what if this becomes a very popular form, with a lot of visitors filling it in? The amount of Updates/Deletes could be massive?

I want to know how you deal with it.


Edit

David asked a good question. What technology I'm using?
I personally use PHP+MySQL, but I feel like it's more generic question. Please share your solutions no matter of what server-side technology you use, as I'm sure the concept can be adapted one way or the other to different technologies.

解决方案

I think the choice between options 1 and 2 comes down to how much data you are storing. I think in most cases the amount of data you are collecting on a form is going to be fairly small (a few kilobytes). In that case, I think storing it in the session data is the way to go. There's not that much overhead in passing that amount of data back and forth. Also, unless your users are on computers where there is a strict security policy in place, the application should work. If you make the page requirements clear users can decide if they want to proceed or not.

If you are storing large amounts of data for the form then a database would be better so you don't need to pass the data back and forth. However, I think this is going to be a fairly rare situation. Even if the application allows the uploading of files you can save those to a temporary location and only write them to the database once the form is completed. The other situation where you might want to use a database is if your form needs to be able to support the user leaving and coming back at a later time to resume the form.

这篇关于如何在单独页面上存储表单数据的部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆