动态表单的设计、存储和检索
自定义动态生成表单背后的设计是什么?
想要实现类似 drupal 的 CCK 的东西。
在控制面板中,表单所有者设计表单中应包含哪些字段以及表单字段应采用的顺序,以及字段的属性,例如“必需:是/否”
一旦设计了表单最终用户填写并提交。
目前我能够让用户创建自定义表单,问题在于表单内容的存储和检索。
通常,当一个人编写一个表单时,谁的数据存储在数据库中,同时也会编写将表单数据输入数据库所需的代码。当表单几乎每次都随着不同的字段而变化时,这段代码该如何编写?
基本上,我需要的是了解数据库设计,无论字段的数量或类型如何,该设计都将允许存储和检索自定义表单。
我不想为每个表单提交都有一个新表,也不想为每个表单手动编写代码。
这些是我需要的主要字段类型
- 文本框
- 选择列表 单选
- 按钮
- 清单
- 日期字段
- 文本区域
下面是我提出的数据库设计
table1
id、formid、type、position、name、value、select(foreign)、multiple
id:该记录的唯一id,自动
formid:唯一的表单id,特定表单中的所有字段将共享相同的formid
类型:它可以是文本框,选择列表,单选......
位置:是第1个字段,第二个,还是第五个?
name:字段的唯一名称
value:如果是文本框,则在此输入默认值。如果字段的类型不需要值,则它保持为空。
select (foreign):如果是选择列表框,则将显示外国 ID 号。
multiple:如果要允许在该列表框中进行多项选择,则该值将为 1,否则将为 null
table2 id, select, value
因此,如果您想要一个选择列表框字段,在 table1 中,您的类型将是 selectbox,并且您将在 table2 中拥有与“select”相关的外键值。
如果你想要一个文本区域,输入 table1 将是文本区域,如果需要默认值,你输入它,否则它将为空
table1 没有所有属性的列表,但你明白了。根据您想要的字段类型,确定您需要填写哪个属性。如果该属性需要存储额外的数据,例如选择列表框,只需做一个关系,就像使用 table2 所做的那样。
为了呈现表单,系统解释数据库中的数据并相应地创建字段。
到目前为止一切都很好,但是,当字段总是在变化时,如何将数据存储在数据库中?
存储此类数据需要什么样的数据库设计?
以上是动态生成表单的正确方法吗?
What is the design behind custom dynamically generated forms?
Would like to implement something like drupal's CCK.
In the control panel, the owner of the form designs what fields should be in the form and in what order the form fields should be in, as well as the field's attributes such as "required: yes/no"
Once the form has been designed the end user fills it and submits.
Currently I'm able to get the user to create the custom form, the problem is with the storage and retrieval of the content of the form.
Usually, when one writes a form, who's data is stored in the db, the code that will be needed to enter the form's data into the database is also written. How is this code to be written when the form is always changing with different fields almost every time?
Basically, what I need is to understand the database design that will allow the storage and retrieval of custom forms, despite the number or type of fields.
I do not want to have a new table for each form submission, nor do I want to manually write code for each form.
These are the main field types that I will need
- Text Box
- Select List
- Radio Buttons
- Checklist
- Date Field
- Text Area
Below is the database design that I came up with
table1
id, formid, type, position, name, value, select(foreign), multiple
id: Unique id for that record, auto
formid: the unique form id, all fields in a particular form will share the same formid
type: it could be textbox, select list, radio ....
position: is the fields the 1st, 2nd, or 5th?
name: the unique name for the field
value: if it is a textbox, the default value is entered here. If the type of field does not need a value, then it stays as a null.
select (foreign): if it is a select list box, then the foreign idnumber will be present.
multiple: if you want to allow multiple selection in that listbox, then the value will be 1 or else it will be null
table2
id, select, value
So, if you want a select list box field, in table1, you will have the type as selectbox, and you will have the value of the foreign key related to "select" in table2.
If you want a text area, type in table1 will be text area, and if need a default value, you enter it, or else it will be null
table1 does not have the list of all attributes, but you get the point. Depending on what field type you want, determines which attribute you will need to fill. If that attribute will need to store extra data, e.g. a select list box, simple do a relation, as it has been done with table2
To render the form, the system interprets the data in the database and create fields accordingly.
So far so good, but, how do you store the data in the database when the fields are always changing?
What sort of db design is needed to store such data?
Is the above the right way of generating forms dynamically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了这个:
http://formutils.riaforge.org/
I found this:
http://formutils.riaforge.org/