将 Coldfusion 结构插入数据库

发布于 2024-09-05 15:01:15 字数 148 浏览 1 评论 0原文

如果我想将联系表单提交保存到数据库,如何将表单范围插入作为提交?我已经有一段时间没有使用 Coldfusion 了。

联系表单根据从网站的哪个部分提交而有所不同,因此需要缩放和处理具有 5 个字段的表单或具有 10 个字段的表单。我只想将数据存储在 blob 表中。

If I wanted to save a contact form submission to the database, how can I insert the form scope in as the submission? It's been some time since I used Coldfusion.

The contact forms vary depending on what part of the site it was submitted from, so it needs to scale and handle a form with 5 fields or one with 10 fields. I just want to store the data in a blob table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

べ繥欢鉨o。 2024-09-12 15:01:15

最节省空间且最简单的恢复原始形状的方法是使用serializeJSON。之后,您可以使用 key:value|key:value 或结构的 XML 表示形式。

Most space efficient way and least complicated to turn back into original shape is using serializeJSON. After that, you can use something like key:value|key:value, or XML representation of your struct.

如果没有 2024-09-12 15:01:15

Cfwddx 也是一种替代方案。

Cfwddx is also an alternative.

燕归巢 2024-09-12 15:01:15

我不知道有没有办法将本机结构存储到数据库中,但是您是否考虑过使用 JSON 将对象表示为键对值,然后从数据库检索它后将其解析为本机结构?

有一些标签/函数可以帮助您将编码和解码为 JSON:

I don't know that there is a way to store a native structure into a database, but have you thought about using JSON to represent your object as key-pair values and then parsing it into a native structure after retrieving it from the database?

There are tags/functions out there that will help you with the encoding and decoding into JSON:

迷爱 2024-09-12 15:01:15

如果您无法将表单字段规范化为正确的表,您可以尝试将它们存储

  • 在 XML 中(SQL Server 很好地支持 XML)、
  • JSON(在普通 varchar 字段中)或
  • ObjectLoad( ) & ObjectSave()(仅限 CF9)存储为 blob。

IIRC 有多种方法可以通过利用 Java 在 CF9 之前的版本中获得对象加载/保存功能。 http://www.riaforge.org/http://cflib.org/ 可能有它。

If you can't normalize the form fields into proper table(s), you can try storing them:

  • in XML (SQL Server supports XML pretty well), or
  • in JSON (in a plain varchar field), or
  • ObjectLoad() & ObjectSave() (CF9 only) to store as blob.

IIRC there are ways to get object load/save functionality in pre-CF9 by tapping into Java. http://www.riaforge.org/ or http://cflib.org/ might have it.

送君千里 2024-09-12 15:01:15

我一直这样做。事实上,为了取证,我有一个脚本来记录工作中在我们网站上提交的每个表单。

您可以对 FORM 范围使用 serializeJSON() 函数,如下所示......

<cfset theForm = serializeJSON(form)>

然后只需将其插入到您的数据库中即可。

如果您想确保其安全(例如,如果表单包含 PII),您还可以使用 encrypt() 函数对 JSON 字符串进行加密。只需用您选择的算法生成一个密钥并将其存储为应用程序变量即可。这样您就可以根据需要加密和解密内容。

I do this one all the time. In fact, for forensics, I have a script that records every form submission on our sites at work.

You can use the serializeJSON() function against the FORM scope like so...

<cfset theForm = serializeJSON(form)>

Then just insert it into your database.

If you want to make it secure - if the form contains PII, for instance - you could also encrypt the JSON string with the encrypt() function. Just generate a secret key in the algorithm of your choice and store it as an application variable. That way you can encrypt and decrypt the contents as needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文